Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2018 Intel Corporation. All rights reserved.
3 : : * Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved.
4 : : * Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5 : : */
6 : :
7 : : /*
8 : : * NVMe/TCP transport
9 : : */
10 : :
11 : : #include "nvme_internal.h"
12 : :
13 : : #include "spdk/endian.h"
14 : : #include "spdk/likely.h"
15 : : #include "spdk/string.h"
16 : : #include "spdk/stdinc.h"
17 : : #include "spdk/crc32.h"
18 : : #include "spdk/assert.h"
19 : : #include "spdk/trace.h"
20 : : #include "spdk/util.h"
21 : : #include "spdk/nvmf.h"
22 : : #include "spdk/dma.h"
23 : :
24 : : #include "spdk_internal/nvme_tcp.h"
25 : : #include "spdk_internal/trace_defs.h"
26 : :
27 : : #define NVME_TCP_RW_BUFFER_SIZE 131072
28 : :
29 : : /* For async connect workloads, allow more time since we are more likely
30 : : * to be processing lots ICREQs at once.
31 : : */
32 : : #define ICREQ_TIMEOUT_SYNC 2 /* in seconds */
33 : : #define ICREQ_TIMEOUT_ASYNC 10 /* in seconds */
34 : :
35 : : #define NVME_TCP_HPDA_DEFAULT 0
36 : : #define NVME_TCP_MAX_R2T_DEFAULT 1
37 : : #define NVME_TCP_PDU_H2C_MIN_DATA_SIZE 4096
38 : :
39 : : /*
40 : : * Maximum value of transport_ack_timeout used by TCP controller
41 : : */
42 : : #define NVME_TCP_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT 31
43 : :
44 : : enum nvme_tcp_qpair_state {
45 : : NVME_TCP_QPAIR_STATE_INVALID = 0,
46 : : NVME_TCP_QPAIR_STATE_INITIALIZING = 1,
47 : : NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_SEND = 2,
48 : : NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_POLL = 3,
49 : : NVME_TCP_QPAIR_STATE_AUTHENTICATING = 4,
50 : : NVME_TCP_QPAIR_STATE_RUNNING = 5,
51 : : NVME_TCP_QPAIR_STATE_EXITING = 6,
52 : : NVME_TCP_QPAIR_STATE_EXITED = 7,
53 : : };
54 : :
55 : : /* NVMe TCP transport extensions for spdk_nvme_ctrlr */
56 : : struct nvme_tcp_ctrlr {
57 : : struct spdk_nvme_ctrlr ctrlr;
58 : : char psk_identity[NVMF_PSK_IDENTITY_LEN];
59 : : uint8_t psk[SPDK_TLS_PSK_MAX_LEN];
60 : : int psk_size;
61 : : char *tls_cipher_suite;
62 : : };
63 : :
64 : : struct nvme_tcp_poll_group {
65 : : struct spdk_nvme_transport_poll_group group;
66 : : struct spdk_sock_group *sock_group;
67 : : uint32_t completions_per_qpair;
68 : : int64_t num_completions;
69 : :
70 : : TAILQ_HEAD(, nvme_tcp_qpair) needs_poll;
71 : : struct spdk_nvme_tcp_stat stats;
72 : : };
73 : :
74 : : /* NVMe TCP qpair extensions for spdk_nvme_qpair */
75 : : struct nvme_tcp_qpair {
76 : : struct spdk_nvme_qpair qpair;
77 : : struct spdk_sock *sock;
78 : :
79 : : TAILQ_HEAD(, nvme_tcp_req) free_reqs;
80 : : TAILQ_HEAD(, nvme_tcp_req) outstanding_reqs;
81 : :
82 : : TAILQ_HEAD(, nvme_tcp_pdu) send_queue;
83 : : struct nvme_tcp_pdu *recv_pdu;
84 : : struct nvme_tcp_pdu *send_pdu; /* only for error pdu and init pdu */
85 : : struct nvme_tcp_pdu *send_pdus; /* Used by tcp_reqs */
86 : : enum nvme_tcp_pdu_recv_state recv_state;
87 : : struct nvme_tcp_req *tcp_reqs;
88 : : struct spdk_nvme_tcp_stat *stats;
89 : :
90 : : uint16_t num_entries;
91 : : uint16_t async_complete;
92 : :
93 : : struct {
94 : : uint16_t host_hdgst_enable: 1;
95 : : uint16_t host_ddgst_enable: 1;
96 : : uint16_t icreq_send_ack: 1;
97 : : uint16_t in_connect_poll: 1;
98 : : uint16_t reserved: 12;
99 : : } flags;
100 : :
101 : : /** Specifies the maximum number of PDU-Data bytes per H2C Data Transfer PDU */
102 : : uint32_t maxh2cdata;
103 : :
104 : : uint32_t maxr2t;
105 : :
106 : : /* 0 based value, which is used to guide the padding */
107 : : uint8_t cpda;
108 : :
109 : : enum nvme_tcp_qpair_state state;
110 : :
111 : : TAILQ_ENTRY(nvme_tcp_qpair) link;
112 : : bool needs_poll;
113 : :
114 : : uint64_t icreq_timeout_tsc;
115 : :
116 : : bool shared_stats;
117 : : };
118 : :
119 : : enum nvme_tcp_req_state {
120 : : NVME_TCP_REQ_FREE,
121 : : NVME_TCP_REQ_ACTIVE,
122 : : NVME_TCP_REQ_ACTIVE_R2T,
123 : : };
124 : :
125 : : struct nvme_tcp_req {
126 : : struct nvme_request *req;
127 : : enum nvme_tcp_req_state state;
128 : : uint16_t cid;
129 : : uint16_t ttag;
130 : : uint32_t datao;
131 : : uint32_t expected_datao;
132 : : uint32_t r2tl_remain;
133 : : uint32_t active_r2ts;
134 : : /* Used to hold a value received from subsequent R2T while we are still
135 : : * waiting for H2C complete */
136 : : uint16_t ttag_r2t_next;
137 : : bool in_capsule_data;
138 : : /* It is used to track whether the req can be safely freed */
139 : : union {
140 : : uint8_t raw;
141 : : struct {
142 : : /* The last send operation completed - kernel released send buffer */
143 : : uint8_t send_ack : 1;
144 : : /* Data transfer completed - target send resp or last data bit */
145 : : uint8_t data_recv : 1;
146 : : /* tcp_req is waiting for completion of the previous send operation (buffer reclaim notification
147 : : * from kernel) to send H2C */
148 : : uint8_t h2c_send_waiting_ack : 1;
149 : : /* tcp_req received subsequent r2t while it is still waiting for send_ack.
150 : : * Rare case, actual when dealing with target that can send several R2T requests.
151 : : * SPDK TCP target sends 1 R2T for the whole data buffer */
152 : : uint8_t r2t_waiting_h2c_complete : 1;
153 : : /* Accel operation is in progress */
154 : : uint8_t in_progress_accel : 1;
155 : : uint8_t domain_in_use: 1;
156 : : uint8_t reserved : 2;
157 : : } bits;
158 : : } ordering;
159 : : struct nvme_tcp_pdu *pdu;
160 : : struct iovec iov[NVME_TCP_MAX_SGL_DESCRIPTORS];
161 : : uint32_t iovcnt;
162 : : /* Used to hold a value received from subsequent R2T while we are still
163 : : * waiting for H2C ack */
164 : : uint32_t r2tl_remain_next;
165 : : struct nvme_tcp_qpair *tqpair;
166 : : TAILQ_ENTRY(nvme_tcp_req) link;
167 : : struct spdk_nvme_cpl rsp;
168 : : uint8_t rsvd1[32];
169 : : };
170 : : SPDK_STATIC_ASSERT(sizeof(struct nvme_tcp_req) % SPDK_CACHE_LINE_SIZE == 0, "unaligned size");
171 : :
172 : : static struct spdk_nvme_tcp_stat g_dummy_stats = {};
173 : :
174 : : static void nvme_tcp_send_h2c_data(struct nvme_tcp_req *tcp_req);
175 : : static int64_t nvme_tcp_poll_group_process_completions(struct spdk_nvme_transport_poll_group
176 : : *tgroup, uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
177 : : static void nvme_tcp_icresp_handle(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu);
178 : : static void nvme_tcp_req_complete(struct nvme_tcp_req *tcp_req, struct nvme_tcp_qpair *tqpair,
179 : : struct spdk_nvme_cpl *rsp, bool print_on_error);
180 : :
181 : : static inline struct nvme_tcp_qpair *
182 : 141484838 : nvme_tcp_qpair(struct spdk_nvme_qpair *qpair)
183 : : {
184 [ + + + - : 141484838 : assert(qpair->trtype == SPDK_NVME_TRANSPORT_TCP);
+ - # # ]
185 : 141484838 : return SPDK_CONTAINEROF(qpair, struct nvme_tcp_qpair, qpair);
186 : : }
187 : :
188 : : static inline struct nvme_tcp_poll_group *
189 : 386738637 : nvme_tcp_poll_group(struct spdk_nvme_transport_poll_group *group)
190 : : {
191 : 386738637 : return SPDK_CONTAINEROF(group, struct nvme_tcp_poll_group, group);
192 : : }
193 : :
194 : : static inline struct nvme_tcp_ctrlr *
195 : 2222 : nvme_tcp_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
196 : : {
197 [ + + + - : 2222 : assert(ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_TCP);
+ - + - #
# ]
198 : 2222 : return SPDK_CONTAINEROF(ctrlr, struct nvme_tcp_ctrlr, ctrlr);
199 : : }
200 : :
201 : : static struct nvme_tcp_req *
202 : 19298827 : nvme_tcp_req_get(struct nvme_tcp_qpair *tqpair)
203 : : {
204 : : struct nvme_tcp_req *tcp_req;
205 : :
206 [ + - + - : 19298827 : tcp_req = TAILQ_FIRST(&tqpair->free_reqs);
+ - ]
207 [ + + ]: 19298827 : if (!tcp_req) {
208 : 433756 : return NULL;
209 : : }
210 : :
211 [ + + + - : 18865071 : assert(tcp_req->state == NVME_TCP_REQ_FREE);
+ - # # ]
212 [ + - + - ]: 18865071 : tcp_req->state = NVME_TCP_REQ_ACTIVE;
213 [ + + + - : 18865071 : TAILQ_REMOVE(&tqpair->free_reqs, tcp_req, link);
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - # # #
# # # # #
# # # # +
- + - + -
+ - + - +
- + - ]
214 [ + - + - ]: 18865071 : tcp_req->datao = 0;
215 [ + - + - ]: 18865071 : tcp_req->expected_datao = 0;
216 [ + - + - ]: 18865071 : tcp_req->req = NULL;
217 [ + - + - ]: 18865071 : tcp_req->in_capsule_data = false;
218 [ + - + - ]: 18865071 : tcp_req->r2tl_remain = 0;
219 [ + - + - ]: 18865071 : tcp_req->r2tl_remain_next = 0;
220 [ + - + - ]: 18865071 : tcp_req->active_r2ts = 0;
221 [ + - + - ]: 18865071 : tcp_req->iovcnt = 0;
222 [ + - + - : 18865071 : tcp_req->ordering.raw = 0;
+ - ]
223 [ + + + - : 18865071 : memset(tcp_req->pdu, 0, sizeof(struct nvme_tcp_pdu));
+ - ]
224 [ + + + - ]: 18865071 : memset(&tcp_req->rsp, 0, sizeof(struct spdk_nvme_cpl));
225 : :
226 : 18865071 : return tcp_req;
227 : 21257 : }
228 : :
229 : : static void
230 : 18865089 : nvme_tcp_req_put(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_req *tcp_req)
231 : : {
232 [ + + + - : 18865089 : assert(tcp_req->state != NVME_TCP_REQ_FREE);
+ - # # ]
233 [ + - + - ]: 18865089 : tcp_req->state = NVME_TCP_REQ_FREE;
234 [ + + + - : 18865089 : TAILQ_INSERT_HEAD(&tqpair->free_reqs, tcp_req, link);
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- # # # #
# # # # #
# + - + -
+ - + - +
- + - + -
+ - ]
235 : 18865089 : }
236 : :
237 : : static inline void
238 : 0 : nvme_tcp_accel_submit_crc32c(struct nvme_tcp_poll_group *tgroup, struct nvme_tcp_req *treq,
239 : : uint32_t *dst, struct iovec *iovs, uint32_t iovcnt, uint32_t seed,
240 : : spdk_nvme_accel_completion_cb cb_fn, void *cb_arg)
241 : : {
242 [ # # # # : 0 : struct spdk_nvme_poll_group *pg = tgroup->group.group;
# # ]
243 : :
244 [ # # # # : 0 : treq->ordering.bits.in_progress_accel = 1;
# # ]
245 [ # # # # : 0 : pg->accel_fn_table.submit_accel_crc32c(pg->ctx, dst, iovs, iovcnt, seed, cb_fn, cb_arg);
# # # # #
# # # #
# ]
246 : 0 : }
247 : :
248 : : static inline void
249 : 820466 : nvme_tcp_accel_finish_sequence(struct nvme_tcp_poll_group *tgroup, struct nvme_tcp_req *treq,
250 : : void *seq, spdk_nvme_accel_completion_cb cb_fn, void *cb_arg)
251 : : {
252 [ # # # # : 820466 : struct spdk_nvme_poll_group *pg = tgroup->group.group;
# # ]
253 : :
254 [ # # # # : 820466 : treq->ordering.bits.in_progress_accel = 1;
# # ]
255 [ # # # # : 820466 : pg->accel_fn_table.finish_sequence(seq, cb_fn, cb_arg);
# # # # #
# ]
256 : 820466 : }
257 : :
258 : : static inline void
259 : 407063 : nvme_tcp_accel_reverse_sequence(struct nvme_tcp_poll_group *tgroup, void *seq)
260 : : {
261 [ # # # # : 407063 : struct spdk_nvme_poll_group *pg = tgroup->group.group;
# # ]
262 : :
263 [ # # # # : 407063 : pg->accel_fn_table.reverse_sequence(seq);
# # # # #
# ]
264 : 407063 : }
265 : :
266 : : static inline int
267 : 820466 : nvme_tcp_accel_append_crc32c(struct nvme_tcp_poll_group *tgroup, void **seq, uint32_t *dst,
268 : : struct iovec *iovs, uint32_t iovcnt, uint32_t seed,
269 : : spdk_nvme_accel_step_cb cb_fn, void *cb_arg)
270 : : {
271 [ # # # # : 820466 : struct spdk_nvme_poll_group *pg = tgroup->group.group;
# # ]
272 : :
273 [ # # # # : 820466 : return pg->accel_fn_table.append_crc32c(pg->ctx, seq, dst, iovs, iovcnt, NULL, NULL,
# # # # #
# # # #
# ]
274 : 0 : seed, cb_fn, cb_arg);
275 : : }
276 : :
277 : : static void
278 : 5572 : nvme_tcp_free_reqs(struct nvme_tcp_qpair *tqpair)
279 : : {
280 [ + - + - ]: 5572 : free(tqpair->tcp_reqs);
281 [ + - + - ]: 5572 : tqpair->tcp_reqs = NULL;
282 : :
283 [ + - + - ]: 5572 : spdk_free(tqpair->send_pdus);
284 [ + - + - ]: 5572 : tqpair->send_pdus = NULL;
285 : 5572 : }
286 : :
287 : : static int
288 : 5581 : nvme_tcp_alloc_reqs(struct nvme_tcp_qpair *tqpair)
289 : : {
290 : : uint16_t i;
291 : : struct nvme_tcp_req *tcp_req;
292 : :
293 [ + - + - : 5581 : tqpair->tcp_reqs = aligned_alloc(SPDK_CACHE_LINE_SIZE,
+ - ]
294 [ + - + - ]: 5581 : tqpair->num_entries * sizeof(*tcp_req));
295 [ + + + - : 5581 : if (tqpair->tcp_reqs == NULL) {
+ - ]
296 : 0 : SPDK_ERRLOG("Failed to allocate tcp_reqs on tqpair=%p\n", tqpair);
297 : 0 : goto fail;
298 : : }
299 : :
300 : : /* Add additional 2 member for the send_pdu, recv_pdu owned by the tqpair */
301 [ + - + - : 5581 : tqpair->send_pdus = spdk_zmalloc((tqpair->num_entries + 2) * sizeof(struct nvme_tcp_pdu),
+ - + - +
- ]
302 : : 0x1000, NULL,
303 : : SPDK_ENV_NUMA_ID_ANY, SPDK_MALLOC_DMA);
304 : :
305 [ + + + - : 5581 : if (tqpair->send_pdus == NULL) {
+ - ]
306 : 0 : SPDK_ERRLOG("Failed to allocate send_pdus on tqpair=%p\n", tqpair);
307 : 0 : goto fail;
308 : : }
309 : :
310 [ + + + - : 5581 : memset(tqpair->tcp_reqs, 0, tqpair->num_entries * sizeof(*tcp_req));
+ - + - +
- ]
311 [ + - + - : 5581 : TAILQ_INIT(&tqpair->send_queue);
+ - + - +
- + - + -
+ - ]
312 [ + - + - : 5581 : TAILQ_INIT(&tqpair->free_reqs);
+ - + - +
- + - + -
+ - ]
313 [ + - + - : 5581 : TAILQ_INIT(&tqpair->outstanding_reqs);
+ - + - +
- + - + -
+ - ]
314 [ + - + - : 5581 : tqpair->qpair.queue_depth = 0;
+ - ]
315 [ + + + - : 728177 : for (i = 0; i < tqpair->num_entries; i++) {
+ + ]
316 [ + - + - : 722596 : tcp_req = &tqpair->tcp_reqs[i];
+ - ]
317 [ + - + - ]: 722596 : tcp_req->cid = i;
318 [ + - + - ]: 722596 : tcp_req->tqpair = tqpair;
319 [ + - + - : 722596 : tcp_req->pdu = &tqpair->send_pdus[i];
+ - + - +
- ]
320 [ + - + - : 722596 : TAILQ_INSERT_TAIL(&tqpair->free_reqs, tcp_req, link);
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
321 : 131930 : }
322 : :
323 [ + - + - : 5581 : tqpair->send_pdu = &tqpair->send_pdus[i];
+ - + - +
- ]
324 [ + - + - : 5581 : tqpair->recv_pdu = &tqpair->send_pdus[i + 1];
+ - + - +
- + - ]
325 : :
326 : 5581 : return 0;
327 : 0 : fail:
328 : 0 : nvme_tcp_free_reqs(tqpair);
329 : 0 : return -ENOMEM;
330 : 1670 : }
331 : :
332 : : static inline void
333 : 94729832 : nvme_tcp_qpair_set_recv_state(struct nvme_tcp_qpair *tqpair,
334 : : enum nvme_tcp_pdu_recv_state state)
335 : : {
336 [ + + + - : 94729832 : if (tqpair->recv_state == state) {
- + ]
337 : 471 : SPDK_ERRLOG("The recv state of tqpair=%p is same with the state(%d) to be set\n",
338 : : tqpair, state);
339 : 471 : return;
340 : : }
341 : :
342 [ + + ]: 94729361 : if (state == NVME_TCP_PDU_RECV_STATE_ERROR) {
343 [ - + # # : 50 : assert(TAILQ_EMPTY(&tqpair->outstanding_reqs));
# # # # #
# ]
344 : 0 : }
345 : :
346 [ - + - + ]: 94729361 : tqpair->recv_state = state;
347 : 74646 : }
348 : :
349 : : static void nvme_tcp_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr);
350 : :
351 : : static void
352 : 20153 : nvme_tcp_ctrlr_disconnect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
353 : : {
354 : 20153 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
355 : : struct nvme_tcp_pdu *pdu;
356 : : int rc;
357 : : struct nvme_tcp_poll_group *group;
358 : :
359 [ + + + + : 20153 : if (tqpair->needs_poll) {
+ - + - ]
360 [ # # # # ]: 11 : group = nvme_tcp_poll_group(qpair->poll_group);
361 [ - + # # : 11 : TAILQ_REMOVE(&group->needs_poll, tqpair, link);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
362 [ # # # # ]: 11 : tqpair->needs_poll = false;
363 : 0 : }
364 : :
365 [ + - ]: 20153 : rc = spdk_sock_close(&tqpair->sock);
366 : :
367 [ + + + - : 20153 : if (tqpair->sock != NULL) {
- + ]
368 [ # # ]: 3 : SPDK_ERRLOG("tqpair=%p, errno=%d, rc=%d\n", tqpair, errno, rc);
369 : : /* Set it to NULL manually */
370 [ # # # # ]: 3 : tqpair->sock = NULL;
371 : 0 : }
372 : :
373 : : /* clear the send_queue */
374 [ + + + - : 20156 : while (!TAILQ_EMPTY(&tqpair->send_queue)) {
+ - - + ]
375 [ # # # # : 3 : pdu = TAILQ_FIRST(&tqpair->send_queue);
# # ]
376 : : /* Remove the pdu from the send_queue to prevent the wrong sending out
377 : : * in the next round connection
378 : : */
379 [ - + # # : 3 : TAILQ_REMOVE(&tqpair->send_queue, pdu, tailq);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
380 : : }
381 : :
382 [ + - ]: 20153 : nvme_tcp_qpair_abort_reqs(qpair, qpair->abort_dnr);
383 : :
384 : : /* If the qpair is marked as asynchronous, let it go through the process_completions() to
385 : : * let any outstanding requests (e.g. those with outstanding accel operations) complete.
386 : : * Otherwise, there's no way of waiting for them, so tqpair->outstanding_reqs has to be
387 : : * empty.
388 : : */
389 [ + + + + ]: 20153 : if (qpair->async) {
390 : 3635 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
391 : 835 : } else {
392 [ + + + - : 16518 : assert(TAILQ_EMPTY(&tqpair->outstanding_reqs));
+ - + - #
# ]
393 : 16518 : nvme_transport_ctrlr_disconnect_qpair_done(qpair);
394 : : }
395 : 20153 : }
396 : :
397 : : static int
398 : 5566 : nvme_tcp_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
399 : : {
400 : 5566 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
401 : :
402 [ + + # # ]: 5566 : assert(qpair != NULL);
403 [ + - ]: 5566 : nvme_tcp_qpair_abort_reqs(qpair, qpair->abort_dnr);
404 [ + + + - : 5566 : assert(TAILQ_EMPTY(&tqpair->outstanding_reqs));
+ - + - #
# ]
405 : :
406 : 5566 : nvme_qpair_deinit(qpair);
407 : 5566 : nvme_tcp_free_reqs(tqpair);
408 [ + + + + : 5566 : if (!tqpair->shared_stats) {
+ - - + ]
409 [ + - + - ]: 4514 : free(tqpair->stats);
410 : 1670 : }
411 : 5566 : free(tqpair);
412 : :
413 : 5566 : return 0;
414 : : }
415 : :
416 : : static int
417 : 2181 : nvme_tcp_ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr)
418 : : {
419 : 2181 : return 0;
420 : : }
421 : :
422 : : static int
423 : 2216 : nvme_tcp_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
424 : : {
425 : 2216 : struct nvme_tcp_ctrlr *tctrlr = nvme_tcp_ctrlr(ctrlr);
426 : :
427 [ + + + - : 2216 : if (ctrlr->adminq) {
+ - ]
428 [ + - + - ]: 2193 : nvme_tcp_ctrlr_delete_io_qpair(ctrlr, ctrlr->adminq);
429 : 835 : }
430 : :
431 : 2216 : nvme_ctrlr_destruct_finish(ctrlr);
432 : :
433 : 2216 : free(tctrlr);
434 : :
435 : 2216 : return 0;
436 : : }
437 : :
438 : : /* If there are queued requests, we assume they are queued because they are waiting
439 : : * for resources to be released. Those resources are almost certainly released in
440 : : * response to a PDU completing. However, to attempt to make forward progress
441 : : * the qpair needs to be polled and we can't rely on another network event to make
442 : : * that happen. Add it to a list of qpairs to poll regardless of network activity.
443 : : *
444 : : * Besides, when tqpair state is NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_POLL or
445 : : * NVME_TCP_QPAIR_STATE_INITIALIZING, need to add it to needs_poll list too to make
446 : : * forward progress in case that the resources are released after icreq's or CONNECT's
447 : : * resp is processed. */
448 : : static void
449 : 20222965 : nvme_tcp_cond_schedule_qpair_polling(struct nvme_tcp_qpair *tqpair)
450 : : {
451 : : struct nvme_tcp_poll_group *pgroup;
452 : :
453 [ + + + + : 20222965 : if (tqpair->needs_poll || !tqpair->qpair.poll_group) {
+ + + - +
- + - + -
+ - ]
454 : 14390249 : return;
455 : : }
456 : :
457 [ + + # # : 5832716 : if (STAILQ_EMPTY(&tqpair->qpair.queued_req) &&
# # # # #
# # # ]
458 [ + + + - : 4241931 : spdk_likely(tqpair->state != NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_POLL &&
# # # # #
# ]
459 : : tqpair->state != NVME_TCP_QPAIR_STATE_INITIALIZING)) {
460 : 4241667 : return;
461 : : }
462 : :
463 [ # # # # : 1591049 : pgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
464 [ # # # # : 1591049 : TAILQ_INSERT_TAIL(&pgroup->needs_poll, tqpair, link);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
465 [ # # # # ]: 1591049 : tqpair->needs_poll = true;
466 : 22927 : }
467 : :
468 : : static void
469 : 19815902 : pdu_write_done(void *cb_arg, int err)
470 : : {
471 : 19815902 : struct nvme_tcp_pdu *pdu = cb_arg;
472 [ + - + - ]: 19815902 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
473 : :
474 : 19815902 : nvme_tcp_cond_schedule_qpair_polling(tqpair);
475 [ + + + - : 19815902 : TAILQ_REMOVE(&tqpair->send_queue, pdu, tailq);
+ - + + +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - ]
476 : :
477 [ + + ]: 19815902 : if (err != 0) {
478 [ # # # # : 1501 : nvme_transport_ctrlr_disconnect_qpair(tqpair->qpair.ctrlr, &tqpair->qpair);
# # # # ]
479 : 1501 : return;
480 : : }
481 : :
482 [ + + + - : 19814401 : assert(pdu->cb_fn != NULL);
+ - # # ]
483 [ + - + - : 19814401 : pdu->cb_fn(pdu->cb_arg);
- + + - +
- + - ]
484 : 22927 : }
485 : :
486 : : static void
487 : 0 : pdu_write_fail(struct nvme_tcp_pdu *pdu, int status)
488 : : {
489 [ # # # # ]: 0 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
490 : :
491 : : /* This function is similar to pdu_write_done(), but it should be called before a PDU is
492 : : * sent over the socket */
493 [ # # # # : 0 : TAILQ_INSERT_TAIL(&tqpair->send_queue, pdu, tailq);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
494 : 0 : pdu_write_done(pdu, status);
495 : 0 : }
496 : :
497 : : static void
498 : 0 : pdu_seq_fail(struct nvme_tcp_pdu *pdu, int status)
499 : : {
500 [ # # # # ]: 0 : struct nvme_tcp_req *treq = pdu->req;
501 : :
502 : 0 : SPDK_ERRLOG("Failed to execute accel sequence: %d\n", status);
503 [ # # # # ]: 0 : nvme_tcp_cond_schedule_qpair_polling(pdu->qpair);
504 [ # # # # : 0 : treq->rsp.status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
# # # # ]
505 [ # # # # : 0 : nvme_tcp_req_complete(treq, treq->tqpair, &treq->rsp, true);
# # ]
506 : 0 : }
507 : :
508 : : static void
509 : 19815971 : _tcp_write_pdu(struct nvme_tcp_pdu *pdu)
510 : : {
511 : 19815971 : uint32_t mapped_length = 0;
512 [ + - + - ]: 19815971 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
513 : :
514 [ + - + - : 19838921 : pdu->sock_req.iovcnt = nvme_tcp_build_iovs(pdu->iov, SPDK_COUNTOF(pdu->iov), pdu,
+ - + - ]
515 [ + - + - : 19815971 : (bool)tqpair->flags.host_hdgst_enable, (bool)tqpair->flags.host_ddgst_enable,
+ - + - ]
516 : : &mapped_length);
517 [ + - + - : 19815971 : TAILQ_INSERT_TAIL(&tqpair->send_queue, pdu, tailq);
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
518 [ + + + - : 19815971 : if (spdk_unlikely(mapped_length < pdu->data_len)) {
+ - ]
519 [ # # # # ]: 0 : SPDK_ERRLOG("could not map the whole %u bytes (mapped only %u bytes)\n", pdu->data_len,
520 : : mapped_length);
521 : 0 : pdu_write_done(pdu, -EINVAL);
522 : 0 : return;
523 : : }
524 [ + - + - : 19815971 : pdu->sock_req.cb_fn = pdu_write_done;
+ - ]
525 [ + - + - : 19815971 : pdu->sock_req.cb_arg = pdu;
+ - ]
526 [ + - + - : 19815971 : tqpair->stats->submitted_requests++;
+ - ]
527 [ + - + - : 19815971 : spdk_sock_writev_async(tqpair->sock, &pdu->sock_req);
+ - ]
528 : 22927 : }
529 : :
530 : : static void
531 : 413403 : tcp_write_pdu_seq_cb(void *ctx, int status)
532 : : {
533 : 413403 : struct nvme_tcp_pdu *pdu = ctx;
534 [ # # # # ]: 413403 : struct nvme_tcp_req *treq = pdu->req;
535 [ # # # # ]: 413403 : struct nvme_request *req = treq->req;
536 : :
537 [ - + # # : 413403 : assert(treq->ordering.bits.in_progress_accel);
# # # # #
# ]
538 [ # # # # : 413403 : treq->ordering.bits.in_progress_accel = 0;
# # ]
539 : :
540 [ # # # # ]: 413403 : req->accel_sequence = NULL;
541 [ - + ]: 413403 : if (spdk_unlikely(status != 0)) {
542 : 0 : pdu_seq_fail(pdu, status);
543 : 0 : return;
544 : : }
545 : :
546 : 413403 : _tcp_write_pdu(pdu);
547 : 0 : }
548 : :
549 : : static void
550 : 19815971 : tcp_write_pdu(struct nvme_tcp_pdu *pdu)
551 : : {
552 [ + - + - ]: 19815971 : struct nvme_tcp_req *treq = pdu->req;
553 [ + - + - ]: 19815971 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
554 : : struct nvme_tcp_poll_group *tgroup;
555 : : struct nvme_request *req;
556 : :
557 [ + + ]: 19815971 : if (spdk_likely(treq != NULL)) {
558 [ + - + - ]: 19810323 : req = treq->req;
559 [ + + + + : 20315563 : if (req->accel_sequence != NULL &&
- + # # ]
560 [ # # # # : 505240 : spdk_nvme_opc_get_data_transfer(req->cmd.opc) == SPDK_NVME_DATA_HOST_TO_CONTROLLER &&
# # ]
561 [ + + # # ]: 426594 : pdu->data_len > 0) {
562 [ - + # # : 413403 : assert(tqpair->qpair.poll_group != NULL);
# # # # #
# ]
563 [ # # # # : 413403 : tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
564 [ # # # # ]: 413403 : nvme_tcp_accel_finish_sequence(tgroup, treq, req->accel_sequence,
565 : 0 : tcp_write_pdu_seq_cb, pdu);
566 : 413403 : return;
567 : : }
568 : 21257 : }
569 : :
570 : 19402568 : _tcp_write_pdu(pdu);
571 : 22927 : }
572 : :
573 : : static void
574 : 0 : pdu_accel_compute_crc32_done(void *cb_arg, int status)
575 : : {
576 : 0 : struct nvme_tcp_pdu *pdu = cb_arg;
577 [ # # # # ]: 0 : struct nvme_tcp_req *req = pdu->req;
578 : :
579 [ # # # # : 0 : assert(req->ordering.bits.in_progress_accel);
# # # # #
# ]
580 [ # # # # : 0 : req->ordering.bits.in_progress_accel = 0;
# # ]
581 : :
582 [ # # ]: 0 : if (spdk_unlikely(status)) {
583 : 0 : SPDK_ERRLOG("Failed to compute the data digest for pdu =%p\n", pdu);
584 : 0 : pdu_write_fail(pdu, status);
585 : 0 : return;
586 : : }
587 : :
588 [ # # # # ]: 0 : pdu->data_digest_crc32 ^= SPDK_CRC32C_XOR;
589 [ # # # # : 0 : MAKE_DIGEST_WORD(pdu->data_digest, pdu->data_digest_crc32);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
590 : :
591 : 0 : _tcp_write_pdu(pdu);
592 : 0 : }
593 : :
594 : : static void
595 : 0 : pdu_accel_compute_crc32_seq_cb(void *cb_arg, int status)
596 : : {
597 : 0 : struct nvme_tcp_pdu *pdu = cb_arg;
598 [ # # # # ]: 0 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
599 [ # # # # : 0 : struct nvme_tcp_poll_group *tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
600 [ # # # # ]: 0 : struct nvme_tcp_req *treq = pdu->req;
601 [ # # # # ]: 0 : struct nvme_request *req = treq->req;
602 : :
603 [ # # # # : 0 : assert(treq->ordering.bits.in_progress_accel);
# # # # #
# ]
604 [ # # # # : 0 : treq->ordering.bits.in_progress_accel = 0;
# # ]
605 : :
606 [ # # # # ]: 0 : req->accel_sequence = NULL;
607 [ # # ]: 0 : if (spdk_unlikely(status != 0)) {
608 : 0 : pdu_seq_fail(pdu, status);
609 : 0 : return;
610 : : }
611 : :
612 [ # # # # : 0 : nvme_tcp_accel_submit_crc32c(tgroup, pdu->req, &pdu->data_digest_crc32,
# # ]
613 [ # # # # : 0 : pdu->data_iov, pdu->data_iovcnt, 0,
# # ]
614 : 0 : pdu_accel_compute_crc32_done, pdu);
615 : 0 : }
616 : :
617 : : static void
618 : 413403 : pdu_accel_seq_compute_crc32_done(void *cb_arg)
619 : : {
620 : 413403 : struct nvme_tcp_pdu *pdu = cb_arg;
621 : :
622 [ # # # # ]: 413403 : pdu->data_digest_crc32 ^= SPDK_CRC32C_XOR;
623 [ # # # # : 413403 : MAKE_DIGEST_WORD(pdu->data_digest, pdu->data_digest_crc32);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
624 : 413403 : }
625 : :
626 : : static bool
627 : 432834 : pdu_accel_compute_crc32(struct nvme_tcp_pdu *pdu)
628 : : {
629 [ # # # # ]: 432834 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
630 [ # # # # : 432834 : struct nvme_tcp_poll_group *tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
631 [ # # # # : 432834 : struct nvme_request *req = ((struct nvme_tcp_req *)pdu->req)->req;
# # # # ]
632 : : int rc;
633 : :
634 : : /* Only support this limited case for the first step */
635 [ + + - + : 432834 : if (spdk_unlikely(nvme_qpair_get_state(&tqpair->qpair) < NVME_QPAIR_CONNECTED ||
+ + - + #
# # # # #
# # # # ]
636 : : pdu->dif_ctx != NULL ||
637 : : pdu->data_len % SPDK_NVME_TCP_DIGEST_ALIGNMENT != 0)) {
638 : 109 : return false;
639 : : }
640 : :
641 [ - + # # : 432725 : if (tqpair->qpair.poll_group == NULL) {
# # # # ]
642 : 0 : return false;
643 : : }
644 : :
645 [ + + # # : 432725 : if (tgroup->group.group->accel_fn_table.append_crc32c != NULL) {
# # # # #
# # # #
# ]
646 [ # # ]: 826806 : rc = nvme_tcp_accel_append_crc32c(tgroup, &req->accel_sequence,
647 [ # # ]: 0 : &pdu->data_digest_crc32,
648 [ # # # # : 413403 : pdu->data_iov, pdu->data_iovcnt, 0,
# # ]
649 : 0 : pdu_accel_seq_compute_crc32_done, pdu);
650 [ - + ]: 413403 : if (spdk_unlikely(rc != 0)) {
651 : : /* If accel is out of resources, fall back to non-accelerated crc32 */
652 [ # # ]: 0 : if (rc == -ENOMEM) {
653 : 0 : return false;
654 : : }
655 : :
656 : 0 : SPDK_ERRLOG("Failed to append crc32c operation: %d\n", rc);
657 : 0 : pdu_write_fail(pdu, rc);
658 : 0 : return true;
659 : : }
660 : :
661 : 413403 : tcp_write_pdu(pdu);
662 : 413403 : return true;
663 [ - + # # : 19322 : } else if (tgroup->group.group->accel_fn_table.submit_accel_crc32c != NULL) {
# # # # #
# # # #
# ]
664 [ # # # # : 0 : if (req->accel_sequence != NULL) {
# # ]
665 [ # # # # : 0 : nvme_tcp_accel_finish_sequence(tgroup, pdu->req, req->accel_sequence,
# # # # ]
666 : 0 : pdu_accel_compute_crc32_seq_cb, pdu);
667 : 0 : } else {
668 [ # # # # : 0 : nvme_tcp_accel_submit_crc32c(tgroup, pdu->req, &pdu->data_digest_crc32,
# # ]
669 [ # # # # : 0 : pdu->data_iov, pdu->data_iovcnt, 0,
# # ]
670 : 0 : pdu_accel_compute_crc32_done, pdu);
671 : : }
672 : :
673 : 0 : return true;
674 : : }
675 : :
676 : 19322 : return false;
677 : 0 : }
678 : :
679 : : static void
680 : 0 : pdu_compute_crc32_seq_cb(void *cb_arg, int status)
681 : : {
682 : 0 : struct nvme_tcp_pdu *pdu = cb_arg;
683 [ # # # # ]: 0 : struct nvme_tcp_req *treq = pdu->req;
684 [ # # # # ]: 0 : struct nvme_request *req = treq->req;
685 : : uint32_t crc32c;
686 : :
687 [ # # # # : 0 : assert(treq->ordering.bits.in_progress_accel);
# # # # #
# ]
688 [ # # # # : 0 : treq->ordering.bits.in_progress_accel = 0;
# # ]
689 : :
690 [ # # # # ]: 0 : req->accel_sequence = NULL;
691 [ # # ]: 0 : if (spdk_unlikely(status != 0)) {
692 : 0 : pdu_seq_fail(pdu, status);
693 : 0 : return;
694 : : }
695 : :
696 : 0 : crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
697 : 0 : crc32c = crc32c ^ SPDK_CRC32C_XOR;
698 [ # # # # : 0 : MAKE_DIGEST_WORD(pdu->data_digest, crc32c);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
699 : :
700 : 0 : _tcp_write_pdu(pdu);
701 : 0 : }
702 : :
703 : : static void
704 : 19815971 : pdu_compute_crc32(struct nvme_tcp_pdu *pdu)
705 : : {
706 [ + - + - ]: 19815971 : struct nvme_tcp_qpair *tqpair = pdu->qpair;
707 : : struct nvme_tcp_poll_group *tgroup;
708 : : struct nvme_request *req;
709 : : uint32_t crc32c;
710 : :
711 : : /* Data Digest */
712 [ + + + + : 19818669 : if (pdu->data_len > 0 && g_nvme_tcp_ddgst[pdu->hdr.common.pdu_type] &&
+ + + + +
- + - + -
+ - + - +
- + - + -
+ - ]
713 [ + - + - ]: 2698 : tqpair->flags.host_ddgst_enable) {
714 [ + + ]: 432834 : if (pdu_accel_compute_crc32(pdu)) {
715 : 413403 : return;
716 : : }
717 : :
718 [ # # # # : 19431 : req = ((struct nvme_tcp_req *)pdu->req)->req;
# # # # ]
719 [ - + # # : 19431 : if (req->accel_sequence != NULL) {
# # ]
720 [ # # # # : 0 : tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
721 [ # # # # : 0 : nvme_tcp_accel_finish_sequence(tgroup, pdu->req, req->accel_sequence,
# # # # ]
722 : 0 : pdu_compute_crc32_seq_cb, pdu);
723 : 0 : return;
724 : : }
725 : :
726 : 19431 : crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
727 : 19431 : crc32c = crc32c ^ SPDK_CRC32C_XOR;
728 [ # # # # : 19431 : MAKE_DIGEST_WORD(pdu->data_digest, crc32c);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
729 : 0 : }
730 : :
731 : 19402568 : tcp_write_pdu(pdu);
732 : 22927 : }
733 : :
734 : : static int
735 : 19815971 : nvme_tcp_qpair_write_pdu(struct nvme_tcp_qpair *tqpair,
736 : : struct nvme_tcp_pdu *pdu,
737 : : nvme_tcp_qpair_xfer_complete_cb cb_fn,
738 : : void *cb_arg)
739 : : {
740 : : int hlen;
741 : : uint32_t crc32c;
742 : :
743 [ + - + - : 19815971 : hlen = pdu->hdr.common.hlen;
+ - + - ]
744 [ + - + - ]: 19815971 : pdu->cb_fn = cb_fn;
745 [ + - + - ]: 19815971 : pdu->cb_arg = cb_arg;
746 [ + - + - ]: 19815971 : pdu->qpair = tqpair;
747 : :
748 : : /* Header Digest */
749 [ + + + + : 19815971 : if (g_nvme_tcp_hdgst[pdu->hdr.common.pdu_type] && tqpair->flags.host_hdgst_enable) {
+ + + - +
- + - + -
+ - + + +
- + - -
+ ]
750 : 61538 : crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
751 [ # # # # : 61538 : MAKE_DIGEST_WORD((uint8_t *)&pdu->hdr.raw[hlen], crc32c);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
752 : 0 : }
753 : :
754 : 19815971 : pdu_compute_crc32(pdu);
755 : :
756 : 19815971 : return 0;
757 : : }
758 : :
759 : : static int
760 : 21542415 : nvme_tcp_try_memory_translation(struct nvme_tcp_req *tcp_req, void **addr, uint32_t length)
761 : : {
762 [ + - + - ]: 21542415 : struct nvme_request *req = tcp_req->req;
763 : 21542415 : struct spdk_memory_domain_translation_result translation = {
764 : : .iov_count = 0,
765 : : .size = sizeof(translation)
766 : : };
767 : : int rc;
768 : :
769 [ + + + - : 21542415 : if (!tcp_req->ordering.bits.domain_in_use) {
+ - - + ]
770 : 21463769 : return 0;
771 : : }
772 : :
773 [ # # # # : 157292 : rc = spdk_memory_domain_translate_data(req->payload.opts->memory_domain,
# # # # #
# ]
774 [ # # # # : 78646 : req->payload.opts->memory_domain_ctx, spdk_memory_domain_get_system_domain(), NULL, *addr, length,
# # # # #
# # # ]
775 : : &translation);
776 [ + - - + : 78646 : if (spdk_unlikely(rc || translation.iov_count != 1)) {
# # ]
777 [ # # ]: 0 : SPDK_ERRLOG("DMA memory translation failed, rc %d, iov_count %u\n", rc, translation.iov_count);
778 : 0 : return -EFAULT;
779 : : }
780 : :
781 [ - + # # : 78646 : assert(length == translation.iov.iov_len);
# # # # ]
782 [ # # # # : 78646 : *addr = translation.iov.iov_base;
# # ]
783 : 78646 : return 0;
784 : 19898 : }
785 : :
786 : : /*
787 : : * Build SGL describing contiguous payload buffer.
788 : : */
789 : : static int
790 : 18455501 : nvme_tcp_build_contig_request(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_req *tcp_req)
791 : : {
792 [ + - + - ]: 18455501 : struct nvme_request *req = tcp_req->req;
793 : :
794 : : /* ubsan complains about applying zero offset to null pointer if contig_or_cb_arg is NULL,
795 : : * so just double cast it to make it go away */
796 [ + - + - : 18455501 : void *addr = (void *)((uintptr_t)req->payload.contig_or_cb_arg + req->payload_offset);
+ - + - +
- ]
797 [ + - + - ]: 18455501 : size_t length = req->payload_size;
798 : : int rc;
799 : :
800 [ + + + + : 18455501 : SPDK_DEBUGLOG(nvme, "enter\n");
+ - ]
801 : :
802 [ + + + - : 18455501 : assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG);
# # ]
803 : 18455501 : rc = nvme_tcp_try_memory_translation(tcp_req, &addr, length);
804 [ - + ]: 18455501 : if (spdk_unlikely(rc)) {
805 : 0 : return rc;
806 : : }
807 : :
808 [ + - + - : 18455501 : tcp_req->iov[0].iov_base = addr;
+ - + - +
- ]
809 [ + - + - : 18455501 : tcp_req->iov[0].iov_len = length;
+ - + - +
- ]
810 [ + - + - ]: 18455501 : tcp_req->iovcnt = 1;
811 : 18455501 : return 0;
812 : 19898 : }
813 : :
814 : : /*
815 : : * Build SGL describing scattered payload buffer.
816 : : */
817 : : static int
818 : 428629 : nvme_tcp_build_sgl_request(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_req *tcp_req)
819 : : {
820 : : int rc;
821 : 428629 : uint32_t length, remaining_size, iovcnt = 0, max_num_sgl;
822 [ # # # # ]: 428629 : struct nvme_request *req = tcp_req->req;
823 : :
824 [ - + - + : 428629 : SPDK_DEBUGLOG(nvme, "enter\n");
# # ]
825 : :
826 [ - + # # : 428629 : assert(req->payload_size != 0);
# # # # ]
827 [ - + # # : 428629 : assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL);
# # ]
828 [ - + # # : 428629 : assert(req->payload.reset_sgl_fn != NULL);
# # # # #
# ]
829 [ - + # # : 428629 : assert(req->payload.next_sge_fn != NULL);
# # # # #
# ]
830 [ # # # # : 428629 : req->payload.reset_sgl_fn(req->payload.contig_or_cb_arg, req->payload_offset);
# # # # #
# # # # #
# # # # #
# ]
831 : :
832 [ # # # # : 428629 : max_num_sgl = spdk_min(req->qpair->ctrlr->max_sges, NVME_TCP_MAX_SGL_DESCRIPTORS);
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
833 [ # # # # ]: 428629 : remaining_size = req->payload_size;
834 : :
835 : 0 : do {
836 : 1621266 : void *addr;
837 : :
838 [ # # # # : 3086914 : rc = req->payload.next_sge_fn(req->payload.contig_or_cb_arg, &addr, &length);
# # # # #
# # # # #
# # ]
839 [ - + ]: 3086914 : if (rc) {
840 : 0 : return -1;
841 : : }
842 : :
843 : 3086914 : rc = nvme_tcp_try_memory_translation(tcp_req, &addr, length);
844 [ - + ]: 3086914 : if (spdk_unlikely(rc)) {
845 : 0 : return rc;
846 : : }
847 : :
848 [ # # ]: 3086914 : length = spdk_min(length, remaining_size);
849 [ # # # # : 3086914 : tcp_req->iov[iovcnt].iov_base = addr;
# # # # #
# ]
850 [ # # # # : 3086914 : tcp_req->iov[iovcnt].iov_len = length;
# # # # #
# ]
851 : 3086914 : remaining_size -= length;
852 : 3086914 : iovcnt++;
853 [ + + + + ]: 3086914 : } while (remaining_size > 0 && iovcnt < max_num_sgl);
854 : :
855 : :
856 : : /* Should be impossible if we did our sgl checks properly up the stack, but do a sanity check here. */
857 [ + + ]: 428629 : if (remaining_size > 0) {
858 : 6 : SPDK_ERRLOG("Failed to construct tcp_req=%p, and the iovcnt=%u, remaining_size=%u\n",
859 : : tcp_req, iovcnt, remaining_size);
860 : 6 : return -1;
861 : : }
862 : :
863 [ # # # # ]: 428623 : tcp_req->iovcnt = iovcnt;
864 : :
865 : 428623 : return 0;
866 : 0 : }
867 : :
868 : : static int
869 : 18865074 : nvme_tcp_req_init(struct nvme_tcp_qpair *tqpair, struct nvme_request *req,
870 : : struct nvme_tcp_req *tcp_req)
871 : : {
872 [ + - + - : 18865074 : struct spdk_nvme_ctrlr *ctrlr = tqpair->qpair.ctrlr;
+ - ]
873 : 18865074 : int rc = 0;
874 : : enum spdk_nvme_data_transfer xfer;
875 : : uint32_t max_in_capsule_data_size;
876 : :
877 [ + - + - ]: 18865074 : tcp_req->req = req;
878 [ + + + + : 18865074 : tcp_req->ordering.bits.domain_in_use = (req->payload.opts && req->payload.opts->memory_domain);
+ - + - #
# # # # #
# # # # +
- + - +
- ]
879 : :
880 [ + - + - : 18865074 : req->cmd.cid = tcp_req->cid;
+ - + - +
- ]
881 [ + - + - ]: 18865074 : req->cmd.psdt = SPDK_NVME_PSDT_SGL_MPTR_CONTIG;
882 [ + - + - : 18865074 : req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_TRANSPORT_DATA_BLOCK;
+ - + - +
- + - ]
883 [ + - + - : 18865074 : req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_TRANSPORT;
+ - + - +
- + - ]
884 [ + - + - : 18865074 : req->cmd.dptr.sgl1.unkeyed.length = req->payload_size;
+ - + - +
- + - + -
+ - + - ]
885 : :
886 [ + + + - : 18865074 : if (spdk_unlikely(req->cmd.opc == SPDK_NVME_OPC_FABRIC)) {
+ + ]
887 [ + - ]: 103864 : struct spdk_nvmf_capsule_cmd *nvmf_cmd = (struct spdk_nvmf_capsule_cmd *)&req->cmd;
888 : :
889 [ + - + - ]: 103864 : xfer = spdk_nvme_opc_get_data_transfer(nvmf_cmd->fctype);
890 : 9185 : } else {
891 [ + - + - ]: 18761210 : xfer = spdk_nvme_opc_get_data_transfer(req->cmd.opc);
892 : : }
893 : :
894 : : /* For c2h delay filling in the iov until the data arrives.
895 : : * For h2c some delay is also possible if data doesn't fit into cmd capsule (not implemented). */
896 [ + + + - ]: 18865074 : if (nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG) {
897 [ + + ]: 18436454 : if (xfer != SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
898 : 9452694 : rc = nvme_tcp_build_contig_request(tqpair, tcp_req);
899 : 16553 : }
900 [ + - # # ]: 449877 : } else if (nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_SGL) {
901 [ + + ]: 428620 : if (xfer != SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
902 : 226853 : rc = nvme_tcp_build_sgl_request(tqpair, tcp_req);
903 : 0 : }
904 : 0 : } else {
905 : 0 : rc = -1;
906 : : }
907 : :
908 [ + + ]: 18865074 : if (rc) {
909 : 3 : return rc;
910 : : }
911 : :
912 [ + + ]: 18865071 : if (xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER) {
913 [ + - + - ]: 8993915 : max_in_capsule_data_size = ctrlr->ioccsz_bytes;
914 [ + + + + : 8993915 : if (spdk_unlikely((req->cmd.opc == SPDK_NVME_OPC_FABRIC) ||
+ + + - +
+ ]
915 : : nvme_qpair_is_admin_queue(&tqpair->qpair))) {
916 : 28593 : max_in_capsule_data_size = SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE;
917 : 3989 : }
918 : :
919 [ + + + - : 8993915 : if (req->payload_size <= max_in_capsule_data_size) {
- + ]
920 [ + - + - : 8047439 : req->cmd.dptr.sgl1.unkeyed.type = SPDK_NVME_SGL_TYPE_DATA_BLOCK;
+ - + - +
- + - ]
921 [ + - + - : 8047439 : req->cmd.dptr.sgl1.unkeyed.subtype = SPDK_NVME_SGL_SUBTYPE_OFFSET;
+ - + - +
- + - ]
922 [ + - + - : 8047439 : req->cmd.dptr.sgl1.address = 0;
+ - + - +
- ]
923 [ + - + - ]: 8047439 : tcp_req->in_capsule_data = true;
924 : 4368 : }
925 : 4368 : }
926 : :
927 : 18865071 : return 0;
928 : 21257 : }
929 : :
930 : : static inline bool
931 : 38658881 : nvme_tcp_req_complete_safe(struct nvme_tcp_req *tcp_req)
932 : : {
933 [ + + + + : 38676798 : if (!(tcp_req->ordering.bits.send_ack && tcp_req->ordering.bits.data_recv &&
+ - + - +
- + - + -
+ + - + ]
934 [ + + + - : 18850059 : !tcp_req->ordering.bits.in_progress_accel)) {
+ - ]
935 : 19808822 : return false;
936 : : }
937 : :
938 [ + + + - : 18850059 : assert(tcp_req->state == NVME_TCP_REQ_ACTIVE);
+ - # # ]
939 [ + + + - : 18850059 : assert(tcp_req->tqpair != NULL);
+ - # # ]
940 [ + + + - : 18850059 : assert(tcp_req->req != NULL);
+ - # # ]
941 : :
942 [ + - + - : 18850059 : nvme_tcp_req_complete(tcp_req, tcp_req->tqpair, &tcp_req->rsp, true);
+ - ]
943 : 18850059 : return true;
944 : 39174 : }
945 : :
946 : : static void
947 : 18863780 : nvme_tcp_qpair_cmd_send_complete(void *cb_arg)
948 : : {
949 : 18863780 : struct nvme_tcp_req *tcp_req = cb_arg;
950 : :
951 [ + + + + : 18863780 : SPDK_DEBUGLOG(nvme, "tcp req %p, cid %u, qid %u\n", tcp_req, tcp_req->cid,
+ - # # #
# # # # #
# # # # #
# ]
952 : : tcp_req->tqpair->qpair.id);
953 [ + - + - : 18863780 : tcp_req->ordering.bits.send_ack = 1;
+ - ]
954 : : /* Handle the r2t case */
955 [ + + + - : 18863780 : if (spdk_unlikely(tcp_req->ordering.bits.h2c_send_waiting_ack)) {
+ - - + ]
956 [ # # # # : 0 : SPDK_DEBUGLOG(nvme, "tcp req %p, send H2C data\n", tcp_req);
# # ]
957 : 0 : nvme_tcp_send_h2c_data(tcp_req);
958 : 0 : } else {
959 [ + + + + : 18863780 : if (tcp_req->in_capsule_data && tcp_req->ordering.bits.domain_in_use) {
+ + + + +
- + - + -
- + ]
960 [ # # # # : 130910 : spdk_memory_domain_invalidate_data(tcp_req->req->payload.opts->memory_domain,
# # # # #
# # # #
# ]
961 [ # # # # : 65455 : tcp_req->req->payload.opts->memory_domain_ctx, tcp_req->iov, tcp_req->iovcnt);
# # # # #
# # # # #
# # # # #
# ]
962 : 0 : }
963 : :
964 : 18863780 : nvme_tcp_req_complete_safe(tcp_req);
965 : : }
966 : 18863780 : }
967 : :
968 : : static int
969 : 18865071 : nvme_tcp_qpair_capsule_cmd_send(struct nvme_tcp_qpair *tqpair,
970 : : struct nvme_tcp_req *tcp_req)
971 : : {
972 : : struct nvme_tcp_pdu *pdu;
973 : : struct spdk_nvme_tcp_cmd *capsule_cmd;
974 : 18865071 : uint32_t plen = 0, alignment;
975 : : uint8_t pdo;
976 : :
977 [ + + + + : 18865071 : SPDK_DEBUGLOG(nvme, "enter\n");
+ - ]
978 [ + - + - ]: 18865071 : pdu = tcp_req->pdu;
979 [ + - + - ]: 18865071 : pdu->req = tcp_req;
980 : :
981 [ + - + - ]: 18865071 : capsule_cmd = &pdu->hdr.capsule_cmd;
982 [ + - + - : 18865071 : capsule_cmd->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD;
+ - ]
983 [ + - + - : 18865071 : plen = capsule_cmd->common.hlen = sizeof(*capsule_cmd);
+ - ]
984 [ + - + - : 18865071 : capsule_cmd->ccsqe = tcp_req->req->cmd;
+ - + - ]
985 : :
986 [ + + + + : 18865071 : SPDK_DEBUGLOG(nvme, "capsule_cmd cid=%u on tqpair(%p)\n", tcp_req->req->cmd.cid, tqpair);
+ - # # #
# # # # #
# # ]
987 : :
988 [ + + + - : 18865071 : if (tqpair->flags.host_hdgst_enable) {
+ - ]
989 [ - + - + : 61535 : SPDK_DEBUGLOG(nvme, "Header digest is enabled for capsule command on tcp_req=%p\n",
# # ]
990 : : tcp_req);
991 [ # # # # : 61535 : capsule_cmd->common.flags |= SPDK_NVME_TCP_CH_FLAGS_HDGSTF;
# # # # ]
992 : 61535 : plen += SPDK_NVME_TCP_DIGEST_LEN;
993 : 0 : }
994 : :
995 [ + + + + : 18865071 : if ((tcp_req->req->payload_size == 0) || !tcp_req->in_capsule_data) {
+ + + - +
+ + - + -
+ - + + ]
996 : 10952351 : goto end;
997 : : }
998 : :
999 : 7912720 : pdo = plen;
1000 [ + - + - ]: 7912720 : pdu->padding_len = 0;
1001 [ + + + - : 7912720 : if (tqpair->cpda) {
- + ]
1002 [ - + # # : 3 : alignment = (tqpair->cpda + 1) << 2;
# # # # #
# ]
1003 [ + - ]: 3 : if (alignment > plen) {
1004 [ # # # # ]: 3 : pdu->padding_len = alignment - plen;
1005 : 3 : pdo = alignment;
1006 : 3 : plen = alignment;
1007 : 0 : }
1008 : 0 : }
1009 : :
1010 [ + - + - : 7912720 : capsule_cmd->common.pdo = pdo;
+ - ]
1011 [ + - + - : 7912720 : plen += tcp_req->req->payload_size;
+ - + - ]
1012 [ + + + - : 7912720 : if (tqpair->flags.host_ddgst_enable) {
+ - ]
1013 [ # # # # : 341393 : capsule_cmd->common.flags |= SPDK_NVME_TCP_CH_FLAGS_DDGSTF;
# # # # ]
1014 : 341393 : plen += SPDK_NVME_TCP_DIGEST_LEN;
1015 : 0 : }
1016 : :
1017 [ + - + - ]: 7912720 : tcp_req->datao = 0;
1018 [ + - + - : 7915418 : nvme_tcp_pdu_set_data_buf(pdu, tcp_req->iov, tcp_req->iovcnt,
+ - ]
1019 [ + - + - : 7912720 : 0, tcp_req->req->payload_size);
+ - + - ]
1020 : 18843814 : end:
1021 [ + - + - : 18865071 : capsule_cmd->common.plen = plen;
+ - ]
1022 : 18865071 : return nvme_tcp_qpair_write_pdu(tqpair, pdu, nvme_tcp_qpair_cmd_send_complete, tcp_req);
1023 : :
1024 : : }
1025 : :
1026 : : static int
1027 : 19298818 : nvme_tcp_qpair_submit_request(struct spdk_nvme_qpair *qpair,
1028 : : struct nvme_request *req)
1029 : : {
1030 : : struct nvme_tcp_qpair *tqpair;
1031 : : struct nvme_tcp_req *tcp_req;
1032 : :
1033 : 19298818 : tqpair = nvme_tcp_qpair(qpair);
1034 [ + + # # ]: 19298818 : assert(tqpair != NULL);
1035 [ + + # # ]: 19298818 : assert(req != NULL);
1036 : :
1037 : 19298818 : tcp_req = nvme_tcp_req_get(tqpair);
1038 [ + + ]: 19298818 : if (!tcp_req) {
1039 [ # # # # : 433753 : tqpair->stats->queued_requests++;
# # ]
1040 : : /* Inform the upper layer to try again later. */
1041 : 433753 : return -EAGAIN;
1042 : : }
1043 : :
1044 [ + + ]: 18865065 : if (spdk_unlikely(nvme_tcp_req_init(tqpair, req, tcp_req))) {
1045 : 3 : SPDK_ERRLOG("nvme_tcp_req_init() failed\n");
1046 : 3 : nvme_tcp_req_put(tqpair, tcp_req);
1047 : 3 : return -1;
1048 : : }
1049 : :
1050 [ + - + - ]: 18865062 : tqpair->qpair.queue_depth++;
1051 [ + + + + : 18865062 : spdk_trace_record(TRACE_NVME_TCP_SUBMIT, qpair->id, 0, (uintptr_t)tcp_req->pdu, req->cb_arg,
+ - + - +
- + - + -
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
1052 : : (uint32_t)req->cmd.cid, (uint32_t)req->cmd.opc,
1053 : : req->cmd.cdw10, req->cmd.cdw11, req->cmd.cdw12, tqpair->qpair.queue_depth);
1054 [ + - + - : 18865062 : TAILQ_INSERT_TAIL(&tqpair->outstanding_reqs, tcp_req, link);
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
1055 : 18865062 : return nvme_tcp_qpair_capsule_cmd_send(tqpair, tcp_req);
1056 : 21257 : }
1057 : :
1058 : : static int
1059 : 2181 : nvme_tcp_qpair_reset(struct spdk_nvme_qpair *qpair)
1060 : : {
1061 : 2181 : return 0;
1062 : : }
1063 : :
1064 : : static void
1065 : 18865086 : nvme_tcp_req_complete(struct nvme_tcp_req *tcp_req,
1066 : : struct nvme_tcp_qpair *tqpair,
1067 : : struct spdk_nvme_cpl *rsp,
1068 : : bool print_on_error)
1069 : : {
1070 : 246852 : struct spdk_nvme_cpl cpl;
1071 : : struct spdk_nvme_qpair *qpair;
1072 : : struct nvme_request *req;
1073 : : bool print_error;
1074 : :
1075 [ + + + - : 18865086 : assert(tcp_req->req != NULL);
+ - # # ]
1076 [ + - + - ]: 18865086 : req = tcp_req->req;
1077 [ + - + - ]: 18865086 : qpair = req->qpair;
1078 : :
1079 [ + + + + : 18865086 : SPDK_DEBUGLOG(nvme, "complete tcp_req(%p) on tqpair=%p\n", tcp_req, tqpair);
+ - ]
1080 : :
1081 [ + + + - : 18865086 : if (!tcp_req->tqpair->qpair.in_completion_context) {
+ - + - +
+ ]
1082 [ + - + - : 417589 : tcp_req->tqpair->async_complete++;
+ - ]
1083 : 3340 : }
1084 : :
1085 : : /* Cache arguments to be passed to nvme_complete_request since tcp_req can be zeroed when released */
1086 [ + - + - ]: 18865086 : memcpy(&cpl, rsp, sizeof(cpl));
1087 : :
1088 [ + + + + : 18865086 : if (spdk_unlikely(spdk_nvme_cpl_is_error(rsp))) {
+ - + + +
- + - + -
+ + ]
1089 [ + + + + : 670890 : print_error = print_on_error && !qpair->ctrlr->opts.disable_error_logging;
+ + + - +
- + - + -
+ - ]
1090 : :
1091 [ + + + + ]: 670890 : if (print_error) {
1092 [ + - ]: 589266 : spdk_nvme_qpair_print_command(qpair, &req->cmd);
1093 : 1898 : }
1094 : :
1095 [ + + + + : 670890 : if (print_error || SPDK_DEBUGLOG_FLAG_ENABLED("nvme")) {
- + ]
1096 : 589290 : spdk_nvme_qpair_print_completion(qpair, rsp);
1097 : 1898 : }
1098 : 5238 : }
1099 : :
1100 [ + - + - ]: 18865086 : tqpair->qpair.queue_depth--;
1101 [ + + + + : 18865086 : spdk_trace_record(TRACE_NVME_TCP_COMPLETE, qpair->id, 0, (uintptr_t)tcp_req->pdu, req->cb_arg,
+ - + - +
- + - + -
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1102 : : (uint32_t)req->cmd.cid, (uint32_t)cpl.status_raw, tqpair->qpair.queue_depth);
1103 [ + + + - : 18865086 : TAILQ_REMOVE(&tcp_req->tqpair->outstanding_reqs, tcp_req, link);
+ - + + +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
1104 : 18865086 : nvme_tcp_req_put(tqpair, tcp_req);
1105 [ + - + - : 18865086 : nvme_complete_request(req->cb_fn, req->cb_arg, req->qpair, req, &cpl);
+ - + - +
- + - ]
1106 : 18865086 : }
1107 : :
1108 : : static void
1109 : 25719 : nvme_tcp_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr)
1110 : : {
1111 : : struct nvme_tcp_req *tcp_req, *tmp;
1112 : 25719 : struct spdk_nvme_cpl cpl = {};
1113 : 25719 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
1114 : :
1115 [ + - + - : 25719 : cpl.sqid = qpair->id;
+ - ]
1116 [ + - + - ]: 25719 : cpl.status.sc = SPDK_NVME_SC_ABORTED_SQ_DELETION;
1117 [ + - + - ]: 25719 : cpl.status.sct = SPDK_NVME_SCT_GENERIC;
1118 [ + - + - ]: 25719 : cpl.status.dnr = dnr;
1119 : :
1120 [ + + + - : 32318 : TAILQ_FOREACH_SAFE(tcp_req, &tqpair->outstanding_reqs, link, tmp) {
+ - + - #
# # # # #
+ - ]
1121 : : /* We cannot abort requests with accel operations in progress */
1122 [ + + # # : 6599 : if (tcp_req->ordering.bits.in_progress_accel) {
# # # # ]
1123 : 6 : continue;
1124 : : }
1125 : :
1126 : 6593 : nvme_tcp_req_complete(tcp_req, tqpair, &cpl, true);
1127 : 0 : }
1128 : 25719 : }
1129 : :
1130 : : static void
1131 : 6 : nvme_tcp_qpair_send_h2c_term_req_complete(void *cb_arg)
1132 : : {
1133 : 6 : struct nvme_tcp_qpair *tqpair = cb_arg;
1134 : :
1135 [ # # # # ]: 6 : tqpair->state = NVME_TCP_QPAIR_STATE_EXITING;
1136 : 6 : }
1137 : :
1138 : : static void
1139 : 51 : nvme_tcp_qpair_send_h2c_term_req(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu,
1140 : : enum spdk_nvme_tcp_term_req_fes fes, uint32_t error_offset)
1141 : : {
1142 : : struct nvme_tcp_pdu *rsp_pdu;
1143 : : struct spdk_nvme_tcp_term_req_hdr *h2c_term_req;
1144 : 51 : uint32_t h2c_term_req_hdr_len = sizeof(*h2c_term_req);
1145 : : uint8_t copy_len;
1146 : :
1147 [ # # # # ]: 51 : rsp_pdu = tqpair->send_pdu;
1148 [ - + ]: 51 : memset(rsp_pdu, 0, sizeof(*rsp_pdu));
1149 [ # # # # ]: 51 : h2c_term_req = &rsp_pdu->hdr.term_req;
1150 [ # # # # : 51 : h2c_term_req->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ;
# # ]
1151 [ # # # # : 51 : h2c_term_req->common.hlen = h2c_term_req_hdr_len;
# # ]
1152 : :
1153 [ + + - + ]: 51 : if ((fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD) ||
1154 : 0 : (fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER)) {
1155 [ # # # # : 45 : DSET32(&h2c_term_req->fei, error_offset);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1156 : 0 : }
1157 : :
1158 [ # # # # : 51 : copy_len = pdu->hdr.common.hlen;
# # # # ]
1159 [ + + ]: 51 : if (copy_len > SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE) {
1160 : 3 : copy_len = SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE;
1161 : 0 : }
1162 : :
1163 : : /* Copy the error info into the buffer */
1164 [ - + - + : 51 : memcpy((uint8_t *)rsp_pdu->hdr.raw + h2c_term_req_hdr_len, pdu->hdr.raw, copy_len);
# # # # #
# # # #
# ]
1165 [ # # # # : 51 : nvme_tcp_pdu_set_data(rsp_pdu, (uint8_t *)rsp_pdu->hdr.raw + h2c_term_req_hdr_len, copy_len);
# # ]
1166 : :
1167 : : /* Contain the header len of the wrong received pdu */
1168 [ # # # # : 51 : h2c_term_req->common.plen = h2c_term_req->common.hlen + copy_len;
# # # # #
# # # ]
1169 : 51 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
1170 : 51 : nvme_tcp_qpair_write_pdu(tqpair, rsp_pdu, nvme_tcp_qpair_send_h2c_term_req_complete, tqpair);
1171 : 51 : }
1172 : :
1173 : : static bool
1174 : 28499719 : nvme_tcp_qpair_recv_state_valid(struct nvme_tcp_qpair *tqpair)
1175 : : {
1176 [ + + + - : 28499719 : switch (tqpair->state) {
+ - ]
1177 : 28478454 : case NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_SEND:
1178 : : case NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_POLL:
1179 : : case NVME_TCP_QPAIR_STATE_AUTHENTICATING:
1180 : : case NVME_TCP_QPAIR_STATE_RUNNING:
1181 : 28499716 : return true;
1182 : 3 : default:
1183 : 3 : return false;
1184 : : }
1185 : 21262 : }
1186 : :
1187 : : static void
1188 : 28505310 : nvme_tcp_pdu_ch_handle(struct nvme_tcp_qpair *tqpair)
1189 : : {
1190 : : struct nvme_tcp_pdu *pdu;
1191 : 28505310 : uint32_t error_offset = 0;
1192 : : enum spdk_nvme_tcp_term_req_fes fes;
1193 : 28505310 : uint32_t expected_hlen, hd_len = 0;
1194 : 28505310 : bool plen_error = false;
1195 : :
1196 [ + - + - ]: 28505310 : pdu = tqpair->recv_pdu;
1197 : :
1198 [ + + + + : 28505310 : SPDK_DEBUGLOG(nvme, "pdu type = %d\n", pdu->hdr.common.pdu_type);
+ - # # #
# # # #
# ]
1199 [ + + + - : 28505310 : if (pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP) {
+ - + - +
+ ]
1200 [ + + + - : 5591 : if (tqpair->state != NVME_TCP_QPAIR_STATE_INVALID) {
- + ]
1201 : 3 : SPDK_ERRLOG("Already received IC_RESP PDU, and we should reject this pdu=%p\n", pdu);
1202 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_PDU_SEQUENCE_ERROR;
1203 : 3 : goto err;
1204 : : }
1205 : 5588 : expected_hlen = sizeof(struct spdk_nvme_tcp_ic_resp);
1206 [ + + + - : 5588 : if (pdu->hdr.common.plen != expected_hlen) {
+ - + - +
- ]
1207 : 3 : plen_error = true;
1208 : 0 : }
1209 : 1670 : } else {
1210 [ + + ]: 28499719 : if (spdk_unlikely(!nvme_tcp_qpair_recv_state_valid(tqpair))) {
1211 : 3 : SPDK_ERRLOG("The TCP/IP tqpair connection is not negotiated\n");
1212 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_PDU_SEQUENCE_ERROR;
1213 : 3 : goto err;
1214 : : }
1215 : :
1216 [ + + + + : 28499716 : switch (pdu->hdr.common.pdu_type) {
+ - + - -
+ + - - ]
1217 : 18331961 : case SPDK_NVME_TCP_PDU_TYPE_CAPSULE_RESP:
1218 : 18349878 : expected_hlen = sizeof(struct spdk_nvme_tcp_rsp);
1219 [ + + + - : 18349878 : if (pdu->hdr.common.flags & SPDK_NVME_TCP_CH_FLAGS_HDGSTF) {
+ - + - +
- + - ]
1220 : 61508 : hd_len = SPDK_NVME_TCP_DIGEST_LEN;
1221 : 0 : }
1222 : :
1223 [ + + + - : 18349878 : if (pdu->hdr.common.plen != (expected_hlen + hd_len)) {
+ - + - +
- ]
1224 : 3 : plen_error = true;
1225 : 0 : }
1226 : 18349878 : break;
1227 : 9201232 : case SPDK_NVME_TCP_PDU_TYPE_C2H_DATA:
1228 : 9204577 : expected_hlen = sizeof(struct spdk_nvme_tcp_c2h_data_hdr);
1229 [ + + + - : 9204577 : if (pdu->hdr.common.plen < pdu->hdr.common.pdo) {
+ - + - +
- + - + -
+ - + - ]
1230 : 3 : plen_error = true;
1231 : 0 : }
1232 : 9204577 : break;
1233 : 3 : case SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ:
1234 : 3 : expected_hlen = sizeof(struct spdk_nvme_tcp_term_req_hdr);
1235 [ - + # # : 3 : if ((pdu->hdr.common.plen <= expected_hlen) ||
# # # # #
# # # ]
1236 [ # # # # : 0 : (pdu->hdr.common.plen > SPDK_NVME_TCP_TERM_REQ_PDU_MAX_SIZE)) {
# # # # ]
1237 : 3 : plen_error = true;
1238 : 0 : }
1239 : 3 : break;
1240 : 945249 : case SPDK_NVME_TCP_PDU_TYPE_R2T:
1241 : 945249 : expected_hlen = sizeof(struct spdk_nvme_tcp_r2t_hdr);
1242 [ + + # # : 945249 : if (pdu->hdr.common.flags & SPDK_NVME_TCP_CH_FLAGS_HDGSTF) {
# # # # #
# # # ]
1243 : 3 : hd_len = SPDK_NVME_TCP_DIGEST_LEN;
1244 : 0 : }
1245 : :
1246 [ + + # # : 945249 : if (pdu->hdr.common.plen != (expected_hlen + hd_len)) {
# # # # #
# ]
1247 : 3 : plen_error = true;
1248 : 0 : }
1249 : 945249 : break;
1250 : :
1251 : 9 : default:
1252 [ # # # # : 9 : SPDK_ERRLOG("Unexpected PDU type 0x%02x\n", tqpair->recv_pdu->hdr.common.pdu_type);
# # # # #
# # # ]
1253 : 9 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1254 : 9 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, pdu_type);
1255 : 9 : goto err;
1256 : : }
1257 : : }
1258 : :
1259 [ + + + - : 28505295 : if (pdu->hdr.common.hlen != expected_hlen) {
+ - + - -
+ ]
1260 [ # # # # : 3 : SPDK_ERRLOG("Expected PDU header length %u, got %u\n",
# # # # ]
1261 : : expected_hlen, pdu->hdr.common.hlen);
1262 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1263 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, hlen);
1264 : 3 : goto err;
1265 : :
1266 [ + + - + ]: 28505292 : } else if (plen_error) {
1267 : 15 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1268 : 15 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, plen);
1269 : 15 : goto err;
1270 : : } else {
1271 : 28505277 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH);
1272 [ + - + - : 28505277 : nvme_tcp_pdu_calc_psh_len(tqpair->recv_pdu, tqpair->flags.host_hdgst_enable);
+ - + - ]
1273 : 28505277 : return;
1274 : : }
1275 : 33 : err:
1276 : 33 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1277 : 22932 : }
1278 : :
1279 : : static struct nvme_tcp_req *
1280 : 28499701 : get_nvme_active_req_by_cid(struct nvme_tcp_qpair *tqpair, uint32_t cid)
1281 : : {
1282 [ + + # # ]: 28499701 : assert(tqpair != NULL);
1283 [ + + + + : 28499701 : if ((cid >= tqpair->num_entries) || (tqpair->tcp_reqs[cid].state == NVME_TCP_REQ_FREE)) {
+ - + - +
- + - + -
+ - - + ]
1284 : 3 : return NULL;
1285 : : }
1286 : :
1287 [ + - + - : 28499698 : return &tqpair->tcp_reqs[cid];
+ - ]
1288 : 21262 : }
1289 : :
1290 : : static void
1291 : 407063 : nvme_tcp_recv_payload_seq_cb(void *cb_arg, int status)
1292 : : {
1293 : 407063 : struct nvme_tcp_req *treq = cb_arg;
1294 [ # # # # ]: 407063 : struct nvme_request *req = treq->req;
1295 [ # # # # ]: 407063 : struct nvme_tcp_qpair *tqpair = treq->tqpair;
1296 : :
1297 [ - + # # : 407063 : assert(treq->ordering.bits.in_progress_accel);
# # # # #
# ]
1298 [ # # # # : 407063 : treq->ordering.bits.in_progress_accel = 0;
# # ]
1299 : :
1300 : 407063 : nvme_tcp_cond_schedule_qpair_polling(tqpair);
1301 : :
1302 [ # # # # ]: 407063 : req->accel_sequence = NULL;
1303 [ - + ]: 407063 : if (spdk_unlikely(status != 0)) {
1304 [ # # # # ]: 0 : pdu_seq_fail(treq->pdu, status);
1305 : 0 : return;
1306 : : }
1307 : :
1308 : 407063 : nvme_tcp_req_complete_safe(treq);
1309 : 0 : }
1310 : :
1311 : : static void
1312 : 9204582 : nvme_tcp_c2h_data_payload_handle(struct nvme_tcp_qpair *tqpair,
1313 : : struct nvme_tcp_pdu *pdu, uint32_t *reaped)
1314 : : {
1315 : : struct nvme_tcp_req *tcp_req;
1316 : : struct nvme_tcp_poll_group *tgroup;
1317 : : struct spdk_nvme_tcp_c2h_data_hdr *c2h_data;
1318 : : uint8_t flags;
1319 : :
1320 [ + - + - ]: 9204582 : tcp_req = pdu->req;
1321 [ + + # # ]: 9204582 : assert(tcp_req != NULL);
1322 : :
1323 [ + + + + : 9204582 : SPDK_DEBUGLOG(nvme, "enter\n");
+ - ]
1324 [ + - + - ]: 9204582 : c2h_data = &pdu->hdr.c2h_data;
1325 [ + - + - : 9204582 : tcp_req->datao += pdu->data_len;
+ - + - ]
1326 [ + - + - : 9204582 : flags = c2h_data->common.flags;
+ - ]
1327 : :
1328 [ + + - + ]: 9204582 : if (flags & SPDK_NVME_TCP_C2H_DATA_FLAGS_LAST_PDU) {
1329 [ + + + - : 8937954 : if (tcp_req->datao == tcp_req->req->payload_size) {
+ - + - +
- + - +
- ]
1330 [ + - + - : 8937384 : tcp_req->rsp.status.p = 0;
+ - + - ]
1331 : 3345 : } else {
1332 [ # # # # : 570 : tcp_req->rsp.status.p = 1;
# # # # ]
1333 : : }
1334 : :
1335 [ + - + - : 8937954 : tcp_req->rsp.cid = tcp_req->cid;
+ - + - +
- ]
1336 [ + - + - : 8937954 : tcp_req->rsp.sqid = tqpair->qpair.id;
+ - + - +
- + - ]
1337 [ + + + - ]: 8937954 : if (flags & SPDK_NVME_TCP_C2H_DATA_FLAGS_SUCCESS) {
1338 [ # # # # : 500172 : tcp_req->ordering.bits.data_recv = 1;
# # ]
1339 [ + + # # : 500172 : if (tcp_req->req->accel_sequence != NULL) {
# # # # #
# ]
1340 [ # # # # : 78646 : tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
1341 [ # # # # : 78646 : nvme_tcp_accel_reverse_sequence(tgroup, tcp_req->req->accel_sequence);
# # # # ]
1342 : 78646 : nvme_tcp_accel_finish_sequence(tgroup, tcp_req,
1343 [ # # # # : 78646 : tcp_req->req->accel_sequence,
# # # # ]
1344 : : nvme_tcp_recv_payload_seq_cb,
1345 : 0 : tcp_req);
1346 : 78646 : return;
1347 : : }
1348 : :
1349 [ + - ]: 421526 : if (nvme_tcp_req_complete_safe(tcp_req)) {
1350 : 421526 : (*reaped)++;
1351 : 0 : }
1352 : 0 : }
1353 : 3345 : }
1354 : 3345 : }
1355 : :
1356 : : static const char *spdk_nvme_tcp_term_req_fes_str[] = {
1357 : : "Invalid PDU Header Field",
1358 : : "PDU Sequence Error",
1359 : : "Header Digest Error",
1360 : : "Data Transfer Out of Range",
1361 : : "Data Transfer Limit Exceeded",
1362 : : "Unsupported parameter",
1363 : : };
1364 : :
1365 : : static void
1366 : 6 : nvme_tcp_c2h_term_req_dump(struct spdk_nvme_tcp_term_req_hdr *c2h_term_req)
1367 : : {
1368 [ # # # # : 6 : SPDK_ERRLOG("Error info of pdu(%p): %s\n", c2h_term_req,
# # # # #
# ]
1369 : : spdk_nvme_tcp_term_req_fes_str[c2h_term_req->fes]);
1370 [ - + # # : 6 : if ((c2h_term_req->fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD) ||
# # # # ]
1371 [ # # # # ]: 0 : (c2h_term_req->fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER)) {
1372 [ - + - + : 6 : SPDK_DEBUGLOG(nvme, "The offset from the start of the PDU header is %u\n",
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
1373 : : DGET32(c2h_term_req->fei));
1374 : 0 : }
1375 : : /* we may also need to dump some other info here */
1376 : 6 : }
1377 : :
1378 : : static void
1379 : 6 : nvme_tcp_c2h_term_req_payload_handle(struct nvme_tcp_qpair *tqpair,
1380 : : struct nvme_tcp_pdu *pdu)
1381 : : {
1382 [ # # # # ]: 6 : nvme_tcp_c2h_term_req_dump(&pdu->hdr.term_req);
1383 : 6 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
1384 : 6 : }
1385 : :
1386 : : static void
1387 : 8797513 : _nvme_tcp_pdu_payload_handle(struct nvme_tcp_qpair *tqpair, uint32_t *reaped)
1388 : : {
1389 : : struct nvme_tcp_pdu *pdu;
1390 : :
1391 [ + + # # ]: 8797513 : assert(tqpair != NULL);
1392 [ + - + - ]: 8797513 : pdu = tqpair->recv_pdu;
1393 : :
1394 [ + + + - : 8797513 : switch (pdu->hdr.common.pdu_type) {
+ - + - -
+ - ]
1395 : 8794165 : case SPDK_NVME_TCP_PDU_TYPE_C2H_DATA:
1396 : 8797510 : nvme_tcp_c2h_data_payload_handle(tqpair, pdu, reaped);
1397 : 8797510 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1398 : 8797510 : break;
1399 : :
1400 : 3 : case SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ:
1401 : 3 : nvme_tcp_c2h_term_req_payload_handle(tqpair, pdu);
1402 : 3 : break;
1403 : :
1404 : 0 : default:
1405 : : /* The code should not go to here */
1406 : 0 : SPDK_ERRLOG("The code should not go to here\n");
1407 : 0 : break;
1408 : : }
1409 : 8797513 : }
1410 : :
1411 : : static void
1412 : 0 : nvme_tcp_accel_recv_compute_crc32_done(void *cb_arg, int status)
1413 : : {
1414 : 0 : struct nvme_tcp_req *tcp_req = cb_arg;
1415 : : struct nvme_tcp_pdu *pdu;
1416 : : struct nvme_tcp_qpair *tqpair;
1417 : : int rc;
1418 : 0 : int dummy_reaped = 0;
1419 : :
1420 [ # # # # ]: 0 : pdu = tcp_req->pdu;
1421 [ # # # # ]: 0 : assert(pdu != NULL);
1422 : :
1423 [ # # # # ]: 0 : tqpair = tcp_req->tqpair;
1424 [ # # # # ]: 0 : assert(tqpair != NULL);
1425 : :
1426 [ # # # # : 0 : assert(tcp_req->ordering.bits.in_progress_accel);
# # # # #
# ]
1427 [ # # # # : 0 : tcp_req->ordering.bits.in_progress_accel = 0;
# # ]
1428 : :
1429 : 0 : nvme_tcp_cond_schedule_qpair_polling(tqpair);
1430 : :
1431 [ # # ]: 0 : if (spdk_unlikely(status)) {
1432 : 0 : SPDK_ERRLOG("Failed to compute the data digest for pdu =%p\n", pdu);
1433 [ # # # # : 0 : tcp_req->rsp.status.sc = SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR;
# # # # ]
1434 : 0 : goto end;
1435 : : }
1436 : :
1437 [ # # # # ]: 0 : pdu->data_digest_crc32 ^= SPDK_CRC32C_XOR;
1438 [ # # # # : 0 : rc = MATCH_DIGEST_WORD(pdu->data_digest, pdu->data_digest_crc32);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1439 [ # # ]: 0 : if (rc == 0) {
1440 : 0 : SPDK_ERRLOG("data digest error on tqpair=(%p) with pdu=%p\n", tqpair, pdu);
1441 [ # # # # : 0 : tcp_req->rsp.status.sc = SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR;
# # # # ]
1442 : 0 : }
1443 : :
1444 : 0 : end:
1445 [ # # # # ]: 0 : nvme_tcp_c2h_data_payload_handle(tqpair, tcp_req->pdu, &dummy_reaped);
1446 : 0 : }
1447 : :
1448 : : static void
1449 : 407063 : nvme_tcp_req_copy_pdu(struct nvme_tcp_req *treq, struct nvme_tcp_pdu *pdu)
1450 : : {
1451 [ # # # # : 407063 : treq->pdu->hdr = pdu->hdr;
# # # # ]
1452 [ # # # # : 407063 : treq->pdu->req = treq;
# # # # ]
1453 [ # # # # : 407063 : memcpy(treq->pdu->data_digest, pdu->data_digest, sizeof(pdu->data_digest));
# # # # #
# # # ]
1454 [ - + - + : 407063 : memcpy(treq->pdu->data_iov, pdu->data_iov, sizeof(pdu->data_iov[0]) * pdu->data_iovcnt);
# # # # #
# # # # #
# # ]
1455 [ # # # # : 407063 : treq->pdu->data_iovcnt = pdu->data_iovcnt;
# # # # #
# # # ]
1456 [ # # # # : 407063 : treq->pdu->data_len = pdu->data_len;
# # # # #
# # # ]
1457 : 407063 : }
1458 : :
1459 : : static void
1460 : 407063 : nvme_tcp_accel_seq_recv_compute_crc32_done(void *cb_arg)
1461 : : {
1462 : 407063 : struct nvme_tcp_req *treq = cb_arg;
1463 [ # # # # ]: 407063 : struct nvme_tcp_qpair *tqpair = treq->tqpair;
1464 [ # # # # ]: 407063 : struct nvme_tcp_pdu *pdu = treq->pdu;
1465 : : bool result;
1466 : :
1467 [ # # # # ]: 407063 : pdu->data_digest_crc32 ^= SPDK_CRC32C_XOR;
1468 [ # # # # : 407063 : result = MATCH_DIGEST_WORD(pdu->data_digest, pdu->data_digest_crc32);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1469 [ + + # # ]: 407063 : if (spdk_unlikely(!result)) {
1470 : 1884 : SPDK_ERRLOG("data digest error on tqpair=(%p)\n", tqpair);
1471 [ # # # # : 1884 : treq->rsp.status.sc = SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR;
# # # # ]
1472 : 0 : }
1473 : 407063 : }
1474 : :
1475 : : static bool
1476 : 619164 : nvme_tcp_accel_recv_compute_crc32(struct nvme_tcp_req *treq, struct nvme_tcp_pdu *pdu)
1477 : : {
1478 [ # # # # ]: 619164 : struct nvme_tcp_qpair *tqpair = treq->tqpair;
1479 [ # # # # : 619164 : struct nvme_tcp_poll_group *tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
1480 [ # # # # ]: 619164 : struct nvme_request *req = treq->req;
1481 : 619164 : int rc, dummy = 0;
1482 : :
1483 : : /* Only support this limited case that the request has only one c2h pdu */
1484 [ + - + + : 619164 : if (spdk_unlikely(nvme_qpair_get_state(&tqpair->qpair) < NVME_QPAIR_CONNECTED ||
+ + - + +
+ - + + +
+ + # # #
# # # # #
# # # # #
# # # # #
# # ]
1485 : : tqpair->qpair.poll_group == NULL || pdu->dif_ctx != NULL ||
1486 : : pdu->data_len % SPDK_NVME_TCP_DIGEST_ALIGNMENT != 0 ||
1487 : : pdu->data_len != req->payload_size)) {
1488 : 192824 : return false;
1489 : : }
1490 : :
1491 [ + + # # : 426340 : if (tgroup->group.group->accel_fn_table.append_crc32c != NULL) {
# # # # #
# # # #
# ]
1492 : 407063 : nvme_tcp_req_copy_pdu(treq, pdu);
1493 [ # # ]: 814126 : rc = nvme_tcp_accel_append_crc32c(tgroup, &req->accel_sequence,
1494 [ # # # # : 407063 : &treq->pdu->data_digest_crc32,
# # ]
1495 [ # # # # : 814126 : treq->pdu->data_iov, treq->pdu->data_iovcnt, 0,
# # # # #
# # # #
# ]
1496 : 0 : nvme_tcp_accel_seq_recv_compute_crc32_done, treq);
1497 [ - + ]: 407063 : if (spdk_unlikely(rc != 0)) {
1498 : : /* If accel is out of resources, fall back to non-accelerated crc32 */
1499 [ # # ]: 0 : if (rc == -ENOMEM) {
1500 : 0 : return false;
1501 : : }
1502 : :
1503 : 0 : SPDK_ERRLOG("Failed to append crc32c operation: %d\n", rc);
1504 [ # # # # : 0 : treq->rsp.status.sc = SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR;
# # # # ]
1505 : 0 : }
1506 : :
1507 : 407063 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1508 [ # # # # ]: 407063 : nvme_tcp_c2h_data_payload_handle(tqpair, treq->pdu, &dummy);
1509 : 407063 : return true;
1510 [ - + # # : 19277 : } else if (tgroup->group.group->accel_fn_table.submit_accel_crc32c != NULL) {
# # # # #
# # # #
# ]
1511 : 0 : nvme_tcp_req_copy_pdu(treq, pdu);
1512 : 0 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1513 [ # # # # : 0 : nvme_tcp_accel_submit_crc32c(tgroup, treq, &treq->pdu->data_digest_crc32,
# # ]
1514 [ # # # # : 0 : treq->pdu->data_iov, treq->pdu->data_iovcnt, 0,
# # # # #
# # # #
# ]
1515 : 0 : nvme_tcp_accel_recv_compute_crc32_done, treq);
1516 : 0 : return true;
1517 : : }
1518 : :
1519 : 19277 : return false;
1520 : 0 : }
1521 : :
1522 : : static void
1523 : 9204576 : nvme_tcp_pdu_payload_handle(struct nvme_tcp_qpair *tqpair,
1524 : : uint32_t *reaped)
1525 : : {
1526 : 9204576 : int rc = 0;
1527 [ + - + - ]: 9204576 : struct nvme_tcp_pdu *pdu = tqpair->recv_pdu;
1528 : : uint32_t crc32c;
1529 [ + - + - ]: 9204576 : struct nvme_tcp_req *tcp_req = pdu->req;
1530 : :
1531 [ + + + - : 9204576 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
+ - # # ]
1532 [ + + + + : 9204576 : SPDK_DEBUGLOG(nvme, "enter\n");
+ - ]
1533 : :
1534 : : /* The request can be NULL, e.g. in case of C2HTermReq */
1535 [ + + ]: 9204576 : if (spdk_likely(tcp_req != NULL)) {
1536 [ + - + - : 9204576 : tcp_req->expected_datao += pdu->data_len;
+ - + - ]
1537 : 3345 : }
1538 : :
1539 : : /* check data digest if need */
1540 [ + + + + : 9204576 : if (pdu->ddgst_enable) {
+ - + - ]
1541 : : /* But if the data digest is enabled, tcp_req cannot be NULL */
1542 [ - + # # ]: 619164 : assert(tcp_req != NULL);
1543 [ + + ]: 619164 : if (nvme_tcp_accel_recv_compute_crc32(tcp_req, pdu)) {
1544 : 407063 : return;
1545 : : }
1546 : :
1547 : 212101 : crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
1548 : 212101 : crc32c = crc32c ^ SPDK_CRC32C_XOR;
1549 [ # # # # : 212101 : rc = MATCH_DIGEST_WORD(pdu->data_digest, crc32c);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1550 [ - + ]: 212101 : if (rc == 0) {
1551 : 0 : SPDK_ERRLOG("data digest error on tqpair=(%p) with pdu=%p\n", tqpair, pdu);
1552 [ # # # # ]: 0 : tcp_req = pdu->req;
1553 [ # # # # ]: 0 : assert(tcp_req != NULL);
1554 [ # # # # : 0 : tcp_req->rsp.status.sc = SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR;
# # # # ]
1555 : 0 : }
1556 : 0 : }
1557 : :
1558 : 8797513 : _nvme_tcp_pdu_payload_handle(tqpair, reaped);
1559 : 3345 : }
1560 : :
1561 : : static void
1562 : 5576 : nvme_tcp_send_icreq_complete(void *cb_arg)
1563 : : {
1564 : 5576 : struct nvme_tcp_qpair *tqpair = cb_arg;
1565 : :
1566 [ + + + + : 5576 : SPDK_DEBUGLOG(nvme, "Complete the icreq send for tqpair=%p %u\n", tqpair, tqpair->qpair.id);
+ - # # #
# # # ]
1567 : :
1568 [ + - + - ]: 5576 : tqpair->flags.icreq_send_ack = true;
1569 : :
1570 [ + + + - : 5576 : if (tqpair->state == NVME_TCP_QPAIR_STATE_INITIALIZING) {
+ - ]
1571 [ # # # # : 0 : SPDK_DEBUGLOG(nvme, "tqpair %p %u, finalize icresp\n", tqpair, tqpair->qpair.id);
# # # # #
# # # ]
1572 [ # # # # ]: 0 : tqpair->state = NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_SEND;
1573 : 0 : }
1574 : 5576 : }
1575 : :
1576 : : static void
1577 : 5594 : nvme_tcp_icresp_handle(struct nvme_tcp_qpair *tqpair,
1578 : : struct nvme_tcp_pdu *pdu)
1579 : : {
1580 [ + - + - ]: 5594 : struct spdk_nvme_tcp_ic_resp *ic_resp = &pdu->hdr.ic_resp;
1581 : 5594 : uint32_t error_offset = 0;
1582 : : enum spdk_nvme_tcp_term_req_fes fes;
1583 : : int recv_buf_size;
1584 : :
1585 : : /* Only PFV 0 is defined currently */
1586 [ + + + - : 5594 : if (ic_resp->pfv != 0) {
- + ]
1587 [ # # # # ]: 3 : SPDK_ERRLOG("Expected ICResp PFV %u, got %u\n", 0u, ic_resp->pfv);
1588 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1589 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_ic_resp, pfv);
1590 : 3 : goto end;
1591 : : }
1592 : :
1593 [ + + + - : 5591 : if (ic_resp->maxh2cdata < NVME_TCP_PDU_H2C_MIN_DATA_SIZE) {
- + ]
1594 [ # # # # ]: 3 : SPDK_ERRLOG("Expected ICResp maxh2cdata >=%u, got %u\n", NVME_TCP_PDU_H2C_MIN_DATA_SIZE,
1595 : : ic_resp->maxh2cdata);
1596 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1597 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_ic_resp, maxh2cdata);
1598 : 3 : goto end;
1599 : : }
1600 [ + - + - : 5588 : tqpair->maxh2cdata = ic_resp->maxh2cdata;
+ - + - ]
1601 : :
1602 [ + + + - : 5588 : if (ic_resp->cpda > SPDK_NVME_TCP_CPDA_MAX) {
- + ]
1603 [ # # # # ]: 3 : SPDK_ERRLOG("Expected ICResp cpda <=%u, got %u\n", SPDK_NVME_TCP_CPDA_MAX, ic_resp->cpda);
1604 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1605 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_ic_resp, cpda);
1606 : 3 : goto end;
1607 : : }
1608 [ + - + - : 5585 : tqpair->cpda = ic_resp->cpda;
+ - + - ]
1609 : :
1610 [ + - + - : 5585 : tqpair->flags.host_hdgst_enable = ic_resp->dgst.bits.hdgst_enable ? true : false;
+ - + - +
- ]
1611 [ + - + - : 5585 : tqpair->flags.host_ddgst_enable = ic_resp->dgst.bits.ddgst_enable ? true : false;
+ - + - +
- ]
1612 [ + + + + : 5585 : SPDK_DEBUGLOG(nvme, "host_hdgst_enable: %u\n", tqpair->flags.host_hdgst_enable);
+ - # # #
# ]
1613 [ + + + + : 5585 : SPDK_DEBUGLOG(nvme, "host_ddgst_enable: %u\n", tqpair->flags.host_ddgst_enable);
+ - # # #
# ]
1614 : :
1615 : : /* Now that we know whether digests are enabled, properly size the receive buffer to
1616 : : * handle several incoming 4K read commands according to SPDK_NVMF_TCP_RECV_BUF_SIZE_FACTOR
1617 : : * parameter. */
1618 : 5585 : recv_buf_size = 0x1000 + sizeof(struct spdk_nvme_tcp_c2h_data_hdr);
1619 : :
1620 [ + + + - : 5585 : if (tqpair->flags.host_hdgst_enable) {
+ - ]
1621 [ # # ]: 30 : recv_buf_size += SPDK_NVME_TCP_DIGEST_LEN;
1622 : 0 : }
1623 : :
1624 [ + + + - : 5585 : if (tqpair->flags.host_ddgst_enable) {
+ - ]
1625 [ # # ]: 106 : recv_buf_size += SPDK_NVME_TCP_DIGEST_LEN;
1626 : 0 : }
1627 : :
1628 [ + + + - : 5585 : if (spdk_sock_set_recvbuf(tqpair->sock, recv_buf_size * SPDK_NVMF_TCP_RECV_BUF_SIZE_FACTOR) < 0) {
+ - + - ]
1629 : 0 : SPDK_WARNLOG("Unable to allocate enough memory for receive buffer on tqpair=%p with size=%d\n",
1630 : : tqpair,
1631 : : recv_buf_size);
1632 : : /* Not fatal. */
1633 : 0 : }
1634 : :
1635 : 5585 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1636 : :
1637 [ + + + - : 5585 : if (!tqpair->flags.icreq_send_ack) {
+ - ]
1638 [ # # # # ]: 3 : tqpair->state = NVME_TCP_QPAIR_STATE_INITIALIZING;
1639 [ - + - + : 3 : SPDK_DEBUGLOG(nvme, "tqpair %p %u, waiting icreq ack\n", tqpair, tqpair->qpair.id);
# # # # #
# # # ]
1640 : 3 : return;
1641 : : }
1642 : :
1643 [ + - + - ]: 5582 : tqpair->state = NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_SEND;
1644 : 5582 : return;
1645 : 9 : end:
1646 : 9 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1647 : 1670 : }
1648 : :
1649 : : static void
1650 : 18349881 : nvme_tcp_capsule_resp_hdr_handle(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu,
1651 : : uint32_t *reaped)
1652 : : {
1653 : : struct nvme_tcp_req *tcp_req;
1654 : : struct nvme_tcp_poll_group *tgroup;
1655 [ + - + - ]: 18349881 : struct spdk_nvme_tcp_rsp *capsule_resp = &pdu->hdr.capsule_resp;
1656 : 18349881 : uint32_t cid, error_offset = 0;
1657 : : enum spdk_nvme_tcp_term_req_fes fes;
1658 : :
1659 [ + + + + : 18349881 : SPDK_DEBUGLOG(nvme, "enter\n");
+ - ]
1660 [ + - + - : 18349881 : cid = capsule_resp->rccqe.cid;
+ - ]
1661 : 18349881 : tcp_req = get_nvme_active_req_by_cid(tqpair, cid);
1662 : :
1663 [ + + ]: 18349881 : if (!tcp_req) {
1664 : 3 : SPDK_ERRLOG("no tcp_req is found with cid=%u for tqpair=%p\n", cid, tqpair);
1665 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1666 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_rsp, rccqe);
1667 : 3 : goto end;
1668 : : }
1669 : :
1670 [ + + + - : 18349878 : assert(tcp_req->req != NULL);
+ - # # ]
1671 : :
1672 [ + - + - ]: 18349878 : tcp_req->rsp = capsule_resp->rccqe;
1673 [ + - + - : 18349878 : tcp_req->ordering.bits.data_recv = 1;
+ - ]
1674 : :
1675 : : /* Recv the pdu again */
1676 : 18349878 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1677 : :
1678 [ + + + - : 18349878 : if (tcp_req->req->accel_sequence != NULL) {
+ - + - -
+ ]
1679 [ # # # # : 328417 : tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
# # ]
1680 [ # # # # : 328417 : nvme_tcp_accel_reverse_sequence(tgroup, tcp_req->req->accel_sequence);
# # # # ]
1681 [ # # # # : 328417 : nvme_tcp_accel_finish_sequence(tgroup, tcp_req, tcp_req->req->accel_sequence,
# # # # ]
1682 : 0 : nvme_tcp_recv_payload_seq_cb, tcp_req);
1683 : 328417 : return;
1684 : : }
1685 : :
1686 [ + + ]: 18021461 : if (nvme_tcp_req_complete_safe(tcp_req)) {
1687 : 18021461 : (*reaped)++;
1688 : 17917 : }
1689 : :
1690 : 18021461 : return;
1691 : :
1692 : 3 : end:
1693 : 3 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1694 : 17917 : }
1695 : :
1696 : : static void
1697 : 0 : nvme_tcp_c2h_term_req_hdr_handle(struct nvme_tcp_qpair *tqpair,
1698 : : struct nvme_tcp_pdu *pdu)
1699 : : {
1700 [ # # # # ]: 0 : struct spdk_nvme_tcp_term_req_hdr *c2h_term_req = &pdu->hdr.term_req;
1701 : 0 : uint32_t error_offset = 0;
1702 : : enum spdk_nvme_tcp_term_req_fes fes;
1703 : :
1704 [ # # # # : 0 : if (c2h_term_req->fes > SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER) {
# # ]
1705 : 0 : SPDK_ERRLOG("Fatal Error Status(FES) is unknown for c2h_term_req pdu=%p\n", pdu);
1706 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1707 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_term_req_hdr, fes);
1708 : 0 : goto end;
1709 : : }
1710 : :
1711 : : /* set the data buffer */
1712 [ # # # # : 0 : nvme_tcp_pdu_set_data(pdu, (uint8_t *)pdu->hdr.raw + c2h_term_req->common.hlen,
# # # # #
# # # ]
1713 [ # # # # : 0 : c2h_term_req->common.plen - c2h_term_req->common.hlen);
# # # # #
# # # ]
1714 : 0 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
1715 : 0 : return;
1716 : 0 : end:
1717 : 0 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1718 : 0 : }
1719 : :
1720 : : static void
1721 : 9204574 : nvme_tcp_c2h_data_hdr_handle(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu)
1722 : : {
1723 : : struct nvme_tcp_req *tcp_req;
1724 [ + - + - ]: 9204574 : struct spdk_nvme_tcp_c2h_data_hdr *c2h_data = &pdu->hdr.c2h_data;
1725 : 9204574 : uint32_t error_offset = 0;
1726 : : enum spdk_nvme_tcp_term_req_fes fes;
1727 [ + - + - : 9204574 : int flags = c2h_data->common.flags;
+ - ]
1728 : : int rc;
1729 : :
1730 [ + + + + : 9204574 : SPDK_DEBUGLOG(nvme, "enter\n");
+ - ]
1731 [ + + + + : 9204574 : SPDK_DEBUGLOG(nvme, "c2h_data info on tqpair(%p): datao=%u, datal=%u, cccid=%d\n",
+ - # # #
# # # # #
# # # # ]
1732 : : tqpair, c2h_data->datao, c2h_data->datal, c2h_data->cccid);
1733 [ + - + - ]: 9204574 : tcp_req = get_nvme_active_req_by_cid(tqpair, c2h_data->cccid);
1734 [ + + ]: 9204574 : if (!tcp_req) {
1735 [ # # # # ]: 0 : SPDK_ERRLOG("no tcp_req found for c2hdata cid=%d\n", c2h_data->cccid);
1736 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1737 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_c2h_data_hdr, cccid);
1738 : 0 : goto end;
1739 : :
1740 : : }
1741 : :
1742 [ + + + + : 9204574 : SPDK_DEBUGLOG(nvme, "tcp_req(%p) on tqpair(%p): expected_datao=%u, payload_size=%u\n",
+ - # # #
# # # # #
# # # # ]
1743 : : tcp_req, tqpair, tcp_req->expected_datao, tcp_req->req->payload_size);
1744 : :
1745 [ + + + + : 9204574 : if (spdk_unlikely((flags & SPDK_NVME_TCP_C2H_DATA_FLAGS_SUCCESS) &&
# # - + ]
1746 : : !(flags & SPDK_NVME_TCP_C2H_DATA_FLAGS_LAST_PDU))) {
1747 : 0 : SPDK_ERRLOG("Invalid flag flags=%d in c2h_data=%p\n", flags, c2h_data);
1748 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1749 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_c2h_data_hdr, common);
1750 : 0 : goto end;
1751 : : }
1752 : :
1753 [ + + + - : 9204574 : if (c2h_data->datal > tcp_req->req->payload_size) {
+ - + - +
- + - -
+ ]
1754 [ # # # # : 0 : SPDK_ERRLOG("Invalid datal for tcp_req(%p), datal(%u) exceeds payload_size(%u)\n",
# # # # #
# # # ]
1755 : : tcp_req, c2h_data->datal, tcp_req->req->payload_size);
1756 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_OUT_OF_RANGE;
1757 : 0 : goto end;
1758 : : }
1759 : :
1760 [ + + + - : 9204574 : if (tcp_req->expected_datao != c2h_data->datao) {
+ - + - -
+ ]
1761 [ # # # # : 0 : SPDK_ERRLOG("Invalid datao for tcp_req(%p), received datal(%u) != expected datao(%u) in tcp_req\n",
# # # # ]
1762 : : tcp_req, c2h_data->datao, tcp_req->expected_datao);
1763 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1764 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_c2h_data_hdr, datao);
1765 : 0 : goto end;
1766 : : }
1767 : :
1768 [ + + + - : 9204574 : if ((c2h_data->datao + c2h_data->datal) > tcp_req->req->payload_size) {
+ - + - +
- + - + -
+ - - + ]
1769 [ # # # # : 0 : SPDK_ERRLOG("Invalid data range for tcp_req(%p), received (datao(%u) + datal(%u)) > datao(%u) in tcp_req\n",
# # # # #
# # # # #
# # ]
1770 : : tcp_req, c2h_data->datao, c2h_data->datal, tcp_req->req->payload_size);
1771 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_OUT_OF_RANGE;
1772 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_c2h_data_hdr, datal);
1773 : 0 : goto end;
1774 : :
1775 : : }
1776 : :
1777 [ + + + - : 9204574 : if (nvme_payload_type(&tcp_req->req->payload) == NVME_PAYLOAD_TYPE_CONTIG) {
+ - + - ]
1778 : 9002807 : rc = nvme_tcp_build_contig_request(tqpair, tcp_req);
1779 : 3345 : } else {
1780 [ - + # # : 201767 : assert(nvme_payload_type(&tcp_req->req->payload) == NVME_PAYLOAD_TYPE_SGL);
# # # # #
# ]
1781 : 201767 : rc = nvme_tcp_build_sgl_request(tqpair, tcp_req);
1782 : : }
1783 : :
1784 [ - + ]: 9204574 : if (rc) {
1785 : : /* Not the right error message but at least it handles the failure. */
1786 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_LIMIT_EXCEEDED;
1787 : 0 : goto end;
1788 : : }
1789 : :
1790 [ + - + - : 9207919 : nvme_tcp_pdu_set_data_buf(pdu, tcp_req->iov, tcp_req->iovcnt,
+ - ]
1791 [ + - + - : 3345 : c2h_data->datao, c2h_data->datal);
+ - + - ]
1792 [ + - + - ]: 9204574 : pdu->req = tcp_req;
1793 : :
1794 : 9204574 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
1795 : 9204574 : return;
1796 : :
1797 : 0 : end:
1798 : 0 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1799 : 3345 : }
1800 : :
1801 : : static void
1802 : 945039 : nvme_tcp_qpair_h2c_data_send_complete(void *cb_arg)
1803 : : {
1804 : 945039 : struct nvme_tcp_req *tcp_req = cb_arg;
1805 : :
1806 [ - + # # ]: 945039 : assert(tcp_req != NULL);
1807 : :
1808 [ # # # # : 945039 : tcp_req->ordering.bits.send_ack = 1;
# # ]
1809 [ - + # # : 945039 : if (tcp_req->r2tl_remain) {
# # ]
1810 : 0 : nvme_tcp_send_h2c_data(tcp_req);
1811 : 0 : } else {
1812 [ - + # # : 945039 : assert(tcp_req->active_r2ts > 0);
# # # # ]
1813 [ # # ]: 945039 : tcp_req->active_r2ts--;
1814 [ # # # # ]: 945039 : tcp_req->state = NVME_TCP_REQ_ACTIVE;
1815 : :
1816 [ - + # # : 945039 : if (tcp_req->ordering.bits.r2t_waiting_h2c_complete) {
# # # # ]
1817 [ # # # # : 0 : tcp_req->ordering.bits.r2t_waiting_h2c_complete = 0;
# # ]
1818 [ # # # # : 0 : SPDK_DEBUGLOG(nvme, "tcp_req %p: continue r2t\n", tcp_req);
# # ]
1819 [ # # # # : 0 : assert(tcp_req->active_r2ts > 0);
# # # # ]
1820 [ # # # # : 0 : tcp_req->ttag = tcp_req->ttag_r2t_next;
# # # # ]
1821 [ # # # # : 0 : tcp_req->r2tl_remain = tcp_req->r2tl_remain_next;
# # # # ]
1822 [ # # # # ]: 0 : tcp_req->state = NVME_TCP_REQ_ACTIVE_R2T;
1823 : 0 : nvme_tcp_send_h2c_data(tcp_req);
1824 : 0 : return;
1825 : : }
1826 : :
1827 [ + + # # : 945039 : if (tcp_req->ordering.bits.domain_in_use) {
# # # # ]
1828 [ # # # # : 26382 : spdk_memory_domain_invalidate_data(tcp_req->req->payload.opts->memory_domain,
# # # # #
# # # #
# ]
1829 [ # # # # : 13191 : tcp_req->req->payload.opts->memory_domain_ctx, tcp_req->iov, tcp_req->iovcnt);
# # # # #
# # # # #
# # # # #
# ]
1830 : 0 : }
1831 : :
1832 : : /* Need also call this function to free the resource */
1833 : 945039 : nvme_tcp_req_complete_safe(tcp_req);
1834 : : }
1835 : 0 : }
1836 : :
1837 : : static void
1838 : 945246 : nvme_tcp_send_h2c_data(struct nvme_tcp_req *tcp_req)
1839 : : {
1840 [ # # # # : 945246 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(tcp_req->req->qpair);
# # # # ]
1841 : : struct nvme_tcp_pdu *rsp_pdu;
1842 : : struct spdk_nvme_tcp_h2c_data_hdr *h2c_data;
1843 : : uint32_t plen, pdo, alignment;
1844 : :
1845 : : /* Reinit the send_ack and h2c_send_waiting_ack bits */
1846 [ # # # # : 945246 : tcp_req->ordering.bits.send_ack = 0;
# # ]
1847 [ # # # # : 945246 : tcp_req->ordering.bits.h2c_send_waiting_ack = 0;
# # ]
1848 [ # # # # ]: 945246 : rsp_pdu = tcp_req->pdu;
1849 [ - + ]: 945246 : memset(rsp_pdu, 0, sizeof(*rsp_pdu));
1850 [ # # # # ]: 945246 : rsp_pdu->req = tcp_req;
1851 [ # # # # ]: 945246 : h2c_data = &rsp_pdu->hdr.h2c_data;
1852 : :
1853 [ # # # # : 945246 : h2c_data->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_H2C_DATA;
# # ]
1854 [ # # # # : 945246 : plen = h2c_data->common.hlen = sizeof(*h2c_data);
# # ]
1855 [ # # # # : 945246 : h2c_data->cccid = tcp_req->cid;
# # # # ]
1856 [ # # # # : 945246 : h2c_data->ttag = tcp_req->ttag;
# # # # ]
1857 [ # # # # : 945246 : h2c_data->datao = tcp_req->datao;
# # # # ]
1858 : :
1859 [ # # # # : 945246 : h2c_data->datal = spdk_min(tcp_req->r2tl_remain, tqpair->maxh2cdata);
# # # # #
# # # # #
# # # # #
# # # ]
1860 [ # # # # : 945246 : nvme_tcp_pdu_set_data_buf(rsp_pdu, tcp_req->iov, tcp_req->iovcnt,
# # ]
1861 [ # # # # : 0 : h2c_data->datao, h2c_data->datal);
# # # # ]
1862 [ # # # # : 945246 : tcp_req->r2tl_remain -= h2c_data->datal;
# # # # ]
1863 : :
1864 [ - + # # : 945246 : if (tqpair->flags.host_hdgst_enable) {
# # ]
1865 [ # # # # : 0 : h2c_data->common.flags |= SPDK_NVME_TCP_CH_FLAGS_HDGSTF;
# # # # ]
1866 : 0 : plen += SPDK_NVME_TCP_DIGEST_LEN;
1867 : 0 : }
1868 : :
1869 [ # # # # ]: 945246 : rsp_pdu->padding_len = 0;
1870 : 945246 : pdo = plen;
1871 [ - + # # : 945246 : if (tqpair->cpda) {
# # ]
1872 [ # # # # : 0 : alignment = (tqpair->cpda + 1) << 2;
# # # # #
# ]
1873 [ # # ]: 0 : if (alignment > plen) {
1874 [ # # # # ]: 0 : rsp_pdu->padding_len = alignment - plen;
1875 : 0 : pdo = plen = alignment;
1876 : 0 : }
1877 : 0 : }
1878 : :
1879 [ # # # # : 945246 : h2c_data->common.pdo = pdo;
# # ]
1880 [ # # # # ]: 945246 : plen += h2c_data->datal;
1881 [ + + # # : 945246 : if (tqpair->flags.host_ddgst_enable) {
# # ]
1882 [ # # # # : 91438 : h2c_data->common.flags |= SPDK_NVME_TCP_CH_FLAGS_DDGSTF;
# # # # ]
1883 : 91438 : plen += SPDK_NVME_TCP_DIGEST_LEN;
1884 : 0 : }
1885 : :
1886 [ # # # # : 945246 : h2c_data->common.plen = plen;
# # ]
1887 [ # # # # : 945246 : tcp_req->datao += h2c_data->datal;
# # # # ]
1888 [ + - # # : 945246 : if (!tcp_req->r2tl_remain) {
# # ]
1889 [ # # # # : 945246 : h2c_data->common.flags |= SPDK_NVME_TCP_H2C_DATA_FLAGS_LAST_PDU;
# # # # ]
1890 : 0 : }
1891 : :
1892 [ - + - + : 945246 : SPDK_DEBUGLOG(nvme, "h2c_data info: datao=%u, datal=%u, pdu_len=%u for tqpair=%p\n",
# # # # #
# # # # #
# # # # #
# ]
1893 : : h2c_data->datao, h2c_data->datal, h2c_data->common.plen, tqpair);
1894 : :
1895 : 945246 : nvme_tcp_qpair_write_pdu(tqpair, rsp_pdu, nvme_tcp_qpair_h2c_data_send_complete, tcp_req);
1896 : 945246 : }
1897 : :
1898 : : static void
1899 : 945246 : nvme_tcp_r2t_hdr_handle(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu)
1900 : : {
1901 : : struct nvme_tcp_req *tcp_req;
1902 [ # # # # ]: 945246 : struct spdk_nvme_tcp_r2t_hdr *r2t = &pdu->hdr.r2t;
1903 : 945246 : uint32_t cid, error_offset = 0;
1904 : : enum spdk_nvme_tcp_term_req_fes fes;
1905 : :
1906 [ - + - + : 945246 : SPDK_DEBUGLOG(nvme, "enter\n");
# # ]
1907 [ # # # # ]: 945246 : cid = r2t->cccid;
1908 : 945246 : tcp_req = get_nvme_active_req_by_cid(tqpair, cid);
1909 [ - + ]: 945246 : if (!tcp_req) {
1910 : 0 : SPDK_ERRLOG("Cannot find tcp_req for tqpair=%p\n", tqpair);
1911 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1912 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_r2t_hdr, cccid);
1913 : 0 : goto end;
1914 : : }
1915 : :
1916 [ - + - + : 945246 : SPDK_DEBUGLOG(nvme, "r2t info: r2to=%u, r2tl=%u for tqpair=%p\n", r2t->r2to, r2t->r2tl,
# # # # #
# # # #
# ]
1917 : : tqpair);
1918 : :
1919 [ + - # # : 945246 : if (tcp_req->state == NVME_TCP_REQ_ACTIVE) {
# # ]
1920 [ - + # # : 945246 : assert(tcp_req->active_r2ts == 0);
# # # # ]
1921 [ # # # # ]: 945246 : tcp_req->state = NVME_TCP_REQ_ACTIVE_R2T;
1922 : 0 : }
1923 : :
1924 [ - + # # : 945246 : if (tcp_req->datao != r2t->r2to) {
# # # # #
# ]
1925 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1926 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_r2t_hdr, r2to);
1927 : 0 : goto end;
1928 : :
1929 : : }
1930 : :
1931 [ - + # # : 945246 : if ((r2t->r2tl + r2t->r2to) > tcp_req->req->payload_size) {
# # # # #
# # # # #
# # # # ]
1932 [ # # # # : 0 : SPDK_ERRLOG("Invalid R2T info for tcp_req=%p: (r2to(%u) + r2tl(%u)) exceeds payload_size(%u)\n",
# # # # #
# # # ]
1933 : : tcp_req, r2t->r2to, r2t->r2tl, tqpair->maxh2cdata);
1934 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_OUT_OF_RANGE;
1935 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_r2t_hdr, r2tl);
1936 : 0 : goto end;
1937 : : }
1938 : :
1939 [ # # ]: 945246 : tcp_req->active_r2ts++;
1940 [ - + # # : 945246 : if (spdk_unlikely(tcp_req->active_r2ts > tqpair->maxr2t)) {
# # # # #
# ]
1941 [ # # # # : 0 : if (tcp_req->state == NVME_TCP_REQ_ACTIVE_R2T && !tcp_req->ordering.bits.send_ack) {
# # # # #
# # # #
# ]
1942 : : /* We receive a subsequent R2T while we are waiting for H2C transfer to complete */
1943 [ # # # # : 0 : SPDK_DEBUGLOG(nvme, "received a subsequent R2T\n");
# # ]
1944 [ # # # # : 0 : assert(tcp_req->active_r2ts == tqpair->maxr2t + 1);
# # # # #
# # # ]
1945 [ # # # # : 0 : tcp_req->ttag_r2t_next = r2t->ttag;
# # # # ]
1946 [ # # # # : 0 : tcp_req->r2tl_remain_next = r2t->r2tl;
# # # # ]
1947 [ # # # # : 0 : tcp_req->ordering.bits.r2t_waiting_h2c_complete = 1;
# # ]
1948 : 0 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1949 : 0 : return;
1950 : : } else {
1951 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_R2T_LIMIT_EXCEEDED;
1952 [ # # # # ]: 0 : SPDK_ERRLOG("Invalid R2T: Maximum number of R2T exceeded! Max: %u for tqpair=%p\n", tqpair->maxr2t,
1953 : : tqpair);
1954 : 0 : goto end;
1955 : : }
1956 : : }
1957 : :
1958 [ # # # # : 945246 : tcp_req->ttag = r2t->ttag;
# # # # ]
1959 [ # # # # : 945246 : tcp_req->r2tl_remain = r2t->r2tl;
# # # # ]
1960 : 945246 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
1961 : :
1962 [ + - # # : 945246 : if (spdk_likely(tcp_req->ordering.bits.send_ack)) {
# # # # ]
1963 : 945246 : nvme_tcp_send_h2c_data(tcp_req);
1964 : 0 : } else {
1965 [ # # # # : 0 : tcp_req->ordering.bits.h2c_send_waiting_ack = 1;
# # ]
1966 : : }
1967 : :
1968 : 945246 : return;
1969 : :
1970 : 0 : end:
1971 : 0 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1972 : :
1973 : 0 : }
1974 : :
1975 : : static void
1976 : 28505274 : nvme_tcp_pdu_psh_handle(struct nvme_tcp_qpair *tqpair, uint32_t *reaped)
1977 : : {
1978 : : struct nvme_tcp_pdu *pdu;
1979 : : int rc;
1980 : 28505274 : uint32_t crc32c, error_offset = 0;
1981 : : enum spdk_nvme_tcp_term_req_fes fes;
1982 : :
1983 [ + + + - : 28505274 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH);
+ - # # ]
1984 [ + - + - ]: 28505274 : pdu = tqpair->recv_pdu;
1985 : :
1986 [ + + + + : 28505274 : SPDK_DEBUGLOG(nvme, "enter: pdu type =%u\n", pdu->hdr.common.pdu_type);
+ - # # #
# # # #
# ]
1987 : : /* check header digest if needed */
1988 [ + + + + : 28505274 : if (pdu->has_hdgst) {
+ - + - ]
1989 : 273508 : crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
1990 [ # # # # : 273508 : rc = MATCH_DIGEST_WORD((uint8_t *)pdu->hdr.raw + pdu->hdr.common.hlen, crc32c);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1991 [ - + ]: 273508 : if (rc == 0) {
1992 : 0 : SPDK_ERRLOG("header digest error on tqpair=(%p) with pdu=%p\n", tqpair, pdu);
1993 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_HDGST_ERROR;
1994 : 0 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
1995 : 0 : return;
1996 : :
1997 : : }
1998 : 0 : }
1999 : :
2000 [ + + + - : 28505274 : switch (pdu->hdr.common.pdu_type) {
+ - + - +
+ + - -
- ]
2001 : 3909 : case SPDK_NVME_TCP_PDU_TYPE_IC_RESP:
2002 : 5579 : nvme_tcp_icresp_handle(tqpair, pdu);
2003 : 5579 : break;
2004 : 18331958 : case SPDK_NVME_TCP_PDU_TYPE_CAPSULE_RESP:
2005 : 18349875 : nvme_tcp_capsule_resp_hdr_handle(tqpair, pdu, reaped);
2006 : 18349875 : break;
2007 : 9201229 : case SPDK_NVME_TCP_PDU_TYPE_C2H_DATA:
2008 : 9204574 : nvme_tcp_c2h_data_hdr_handle(tqpair, pdu);
2009 : 9204574 : break;
2010 : :
2011 : 0 : case SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ:
2012 : 0 : nvme_tcp_c2h_term_req_hdr_handle(tqpair, pdu);
2013 : 0 : break;
2014 : 945246 : case SPDK_NVME_TCP_PDU_TYPE_R2T:
2015 : 945246 : nvme_tcp_r2t_hdr_handle(tqpair, pdu);
2016 : 945246 : break;
2017 : :
2018 : 0 : default:
2019 [ # # # # : 0 : SPDK_ERRLOG("Unexpected PDU type 0x%02x\n", tqpair->recv_pdu->hdr.common.pdu_type);
# # # # #
# # # ]
2020 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2021 : 0 : error_offset = 1;
2022 : 0 : nvme_tcp_qpair_send_h2c_term_req(tqpair, pdu, fes, error_offset);
2023 : 0 : break;
2024 : : }
2025 : :
2026 : 22932 : }
2027 : :
2028 : : static int
2029 : 73668747 : nvme_tcp_read_pdu(struct nvme_tcp_qpair *tqpair, uint32_t *reaped, uint32_t max_completions)
2030 : : {
2031 : 73668747 : int rc = 0;
2032 : : struct nvme_tcp_pdu *pdu;
2033 : : uint32_t data_len;
2034 : : enum nvme_tcp_pdu_recv_state prev_state;
2035 : :
2036 [ + - + - : 73668747 : *reaped = tqpair->async_complete;
+ - ]
2037 [ + - + - ]: 73668747 : tqpair->async_complete = 0;
2038 : :
2039 : : /* The loop here is to allow for several back-to-back state changes. */
2040 : 1337795 : do {
2041 [ + + - + ]: 168394821 : if (*reaped >= max_completions) {
2042 : 334592 : break;
2043 : : }
2044 : :
2045 [ + - + - ]: 168060229 : prev_state = tqpair->recv_state;
2046 [ + - + - ]: 168060229 : pdu = tqpair->recv_pdu;
2047 [ + + + + : 168060229 : switch (tqpair->recv_state) {
+ + + + -
- - ]
2048 : : /* If in a new state */
2049 : 28486196 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY:
2050 [ + + ]: 28510798 : memset(pdu, 0, sizeof(struct nvme_tcp_pdu));
2051 : 28510798 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH);
2052 : 28510798 : break;
2053 : : /* Wait for the pdu common header */
2054 : 91731881 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH:
2055 [ + + + - : 93092608 : assert(pdu->ch_valid_bytes < sizeof(struct spdk_nvme_tcp_common_pdu_hdr));
+ - # # ]
2056 [ + - + - ]: 94453335 : rc = nvme_tcp_read_data(tqpair->sock,
2057 [ + - + - ]: 93092608 : sizeof(struct spdk_nvme_tcp_common_pdu_hdr) - pdu->ch_valid_bytes,
2058 [ + - + - : 93092608 : (uint8_t *)&pdu->hdr.common + pdu->ch_valid_bytes);
+ - + - +
- ]
2059 [ + + ]: 93092608 : if (rc < 0) {
2060 : 99 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2061 : 99 : break;
2062 : : }
2063 [ + - + - : 93092509 : pdu->ch_valid_bytes += rc;
+ - ]
2064 [ + + + - : 93092509 : if (pdu->ch_valid_bytes < sizeof(struct spdk_nvme_tcp_common_pdu_hdr)) {
+ + ]
2065 : 64587229 : return NVME_TCP_PDU_IN_PROGRESS;
2066 : : }
2067 : :
2068 : : /* The command header of this PDU has now been read from the socket. */
2069 : 28505280 : nvme_tcp_pdu_ch_handle(tqpair);
2070 : 28505280 : break;
2071 : : /* Wait for the pdu specific header */
2072 : 28482720 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH:
2073 [ + + + - : 28505652 : assert(pdu->psh_valid_bytes < pdu->psh_len);
+ - + - +
- # # ]
2074 [ + - + - ]: 28528584 : rc = nvme_tcp_read_data(tqpair->sock,
2075 [ + - + - : 28505652 : pdu->psh_len - pdu->psh_valid_bytes,
+ - + - ]
2076 [ + - + - : 28505652 : (uint8_t *)&pdu->hdr.raw + sizeof(struct spdk_nvme_tcp_common_pdu_hdr) + pdu->psh_valid_bytes);
+ - + - +
- + - ]
2077 [ + + ]: 28505652 : if (rc < 0) {
2078 : 0 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2079 : 0 : break;
2080 : : }
2081 : :
2082 [ + - + - : 28505652 : pdu->psh_valid_bytes += rc;
+ - ]
2083 [ + + + - : 28505652 : if (pdu->psh_valid_bytes < pdu->psh_len) {
+ - + - +
- ]
2084 : 378 : return NVME_TCP_PDU_IN_PROGRESS;
2085 : : }
2086 : :
2087 : : /* All header(ch, psh, head digits) of this PDU has now been read from the socket. */
2088 : 28505274 : nvme_tcp_pdu_psh_handle(tqpair, reaped);
2089 : 28505274 : break;
2090 : 17947487 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD:
2091 : : /* check whether the data is valid, if not we just return */
2092 [ + + + - : 17950832 : if (!pdu->data_len) {
- + ]
2093 : 0 : return NVME_TCP_PDU_IN_PROGRESS;
2094 : : }
2095 : :
2096 [ + - + - ]: 17950832 : data_len = pdu->data_len;
2097 : : /* data digest */
2098 [ + - + + : 17950832 : if (spdk_unlikely((pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_C2H_DATA) &&
+ - + - -
+ + - + -
+ - ]
2099 : : tqpair->flags.host_ddgst_enable)) {
2100 : 969451 : data_len += SPDK_NVME_TCP_DIGEST_LEN;
2101 [ # # # # ]: 969451 : pdu->ddgst_enable = true;
2102 : 0 : }
2103 : :
2104 [ + - + - ]: 17950832 : rc = nvme_tcp_read_payload_data(tqpair->sock, pdu);
2105 [ + + ]: 17950832 : if (rc < 0) {
2106 : 3 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2107 : 3 : break;
2108 : : }
2109 : :
2110 [ + - + - ]: 17950829 : pdu->rw_offset += rc;
2111 [ + + + - : 17950829 : if (pdu->rw_offset < data_len) {
- + ]
2112 : 8746259 : return NVME_TCP_PDU_IN_PROGRESS;
2113 : : }
2114 : :
2115 [ + + + - : 9204570 : assert(pdu->rw_offset == data_len);
- + # # ]
2116 : : /* All of this PDU has now been read from the socket. */
2117 : 9204570 : nvme_tcp_pdu_payload_handle(tqpair, reaped);
2118 : 9204570 : break;
2119 : 289 : case NVME_TCP_PDU_RECV_STATE_QUIESCING:
2120 [ + + # # : 289 : if (TAILQ_EMPTY(&tqpair->outstanding_reqs)) {
# # # # ]
2121 [ + + # # ]: 50 : if (nvme_qpair_get_state(&tqpair->qpair) == NVME_QPAIR_DISCONNECTING) {
2122 [ # # ]: 41 : nvme_transport_ctrlr_disconnect_qpair_done(&tqpair->qpair);
2123 : 0 : }
2124 : :
2125 : 50 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_ERROR);
2126 : 0 : }
2127 : 289 : break;
2128 : 50 : case NVME_TCP_PDU_RECV_STATE_ERROR:
2129 [ - + ]: 50 : memset(pdu, 0, sizeof(struct nvme_tcp_pdu));
2130 : 50 : return NVME_TCP_PDU_FATAL;
2131 : 0 : default:
2132 [ # # ]: 0 : assert(0);
2133 : : break;
2134 : : }
2135 [ + + + - : 94726313 : } while (prev_state != tqpair->recv_state);
+ - ]
2136 : :
2137 [ # # ]: 334831 : return rc > 0 ? 0 : rc;
2138 : 1337795 : }
2139 : :
2140 : : static void
2141 : 0 : nvme_tcp_qpair_check_timeout(struct spdk_nvme_qpair *qpair)
2142 : : {
2143 : : uint64_t t02;
2144 : : struct nvme_tcp_req *tcp_req, *tmp;
2145 : 0 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2146 [ # # # # ]: 0 : struct spdk_nvme_ctrlr *ctrlr = qpair->ctrlr;
2147 : : struct spdk_nvme_ctrlr_process *active_proc;
2148 : :
2149 : : /* Don't check timeouts during controller initialization. */
2150 [ # # # # : 0 : if (ctrlr->state != NVME_CTRLR_STATE_READY) {
# # ]
2151 : 0 : return;
2152 : : }
2153 : :
2154 [ # # ]: 0 : if (nvme_qpair_is_admin_queue(qpair)) {
2155 : 0 : active_proc = nvme_ctrlr_get_current_process(ctrlr);
2156 : 0 : } else {
2157 [ # # # # ]: 0 : active_proc = qpair->active_proc;
2158 : : }
2159 : :
2160 : : /* Only check timeouts if the current process has a timeout callback. */
2161 [ # # # # : 0 : if (active_proc == NULL || active_proc->timeout_cb_fn == NULL) {
# # # # ]
2162 : 0 : return;
2163 : : }
2164 : :
2165 : 0 : t02 = spdk_get_ticks();
2166 [ # # # # : 0 : TAILQ_FOREACH_SAFE(tcp_req, &tqpair->outstanding_reqs, link, tmp) {
# # # # #
# # # # #
# # ]
2167 [ # # # # : 0 : if (ctrlr->is_failed) {
# # # # ]
2168 : : /* The controller state may be changed to failed in one of the nvme_request_check_timeout callbacks. */
2169 : 0 : return;
2170 : : }
2171 [ # # # # : 0 : assert(tcp_req->req != NULL);
# # # # ]
2172 : :
2173 [ # # # # : 0 : if (nvme_request_check_timeout(tcp_req->req, tcp_req->cid, active_proc, t02)) {
# # # # #
# ]
2174 : : /*
2175 : : * The requests are in order, so as soon as one has not timed out,
2176 : : * stop iterating.
2177 : : */
2178 : 0 : break;
2179 : : }
2180 : 0 : }
2181 : 0 : }
2182 : :
2183 : : static int nvme_tcp_ctrlr_connect_qpair_poll(struct spdk_nvme_ctrlr *ctrlr,
2184 : : struct spdk_nvme_qpair *qpair);
2185 : :
2186 : : static int
2187 : 73669234 : nvme_tcp_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_completions)
2188 : : {
2189 : 73669234 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2190 : 604194 : uint32_t reaped;
2191 : : int rc;
2192 : :
2193 [ + + + - : 73669234 : if (qpair->poll_group == NULL) {
- + ]
2194 [ + - + - ]: 38624682 : rc = spdk_sock_flush(tqpair->sock);
2195 [ + + + + : 38624682 : if (rc < 0 && errno != EAGAIN) {
# # ]
2196 [ # # # # ]: 487 : SPDK_ERRLOG("Failed to flush tqpair=%p (%d): %s\n", tqpair,
2197 : : errno, spdk_strerror(errno));
2198 [ - + - + : 487 : if (spdk_unlikely(tqpair->qpair.ctrlr->timeout_enabled)) {
# # # # #
# # # #
# ]
2199 : 0 : nvme_tcp_qpair_check_timeout(qpair);
2200 : 0 : }
2201 : :
2202 [ + + ]: 487 : if (nvme_qpair_get_state(qpair) == NVME_QPAIR_DISCONNECTING) {
2203 [ + - # # : 469 : if (TAILQ_EMPTY(&tqpair->outstanding_reqs)) {
# # # # ]
2204 : 469 : nvme_transport_ctrlr_disconnect_qpair_done(qpair);
2205 : 0 : }
2206 : :
2207 : : /* Don't return errors until the qpair gets disconnected */
2208 : 469 : return 0;
2209 : : }
2210 : :
2211 : 18 : goto fail;
2212 : : }
2213 : 1337795 : }
2214 : :
2215 [ + + ]: 73668747 : if (max_completions == 0) {
2216 [ + - + - : 68787515 : max_completions = spdk_max(tqpair->num_entries, 1);
+ - + - +
- ]
2217 : 1337795 : } else {
2218 [ # # # # : 4881232 : max_completions = spdk_min(max_completions, tqpair->num_entries);
# # # # #
# ]
2219 : : }
2220 : :
2221 : 73668747 : reaped = 0;
2222 : 73668747 : rc = nvme_tcp_read_pdu(tqpair, &reaped, max_completions);
2223 [ + + ]: 73668747 : if (rc < 0) {
2224 [ - + - + : 143 : SPDK_DEBUGLOG(nvme, "Error polling CQ! (%d): %s\n",
# # # # #
# ]
2225 : : errno, spdk_strerror(errno));
2226 : 143 : goto fail;
2227 : : }
2228 : :
2229 [ + + + + : 73668604 : if (spdk_unlikely(tqpair->qpair.ctrlr->timeout_enabled)) {
+ - + - +
- + - +
- ]
2230 : 0 : nvme_tcp_qpair_check_timeout(qpair);
2231 : 0 : }
2232 : :
2233 [ + + ]: 73668604 : if (spdk_unlikely(nvme_qpair_get_state(qpair) == NVME_QPAIR_CONNECTING)) {
2234 [ + - + - ]: 8046025 : rc = nvme_tcp_ctrlr_connect_qpair_poll(qpair->ctrlr, qpair);
2235 [ + + + + ]: 8046025 : if (rc != 0 && rc != -EAGAIN) {
2236 : 51 : SPDK_ERRLOG("Failed to connect tqpair=%p\n", tqpair);
2237 : 51 : goto fail;
2238 [ + + ]: 8045974 : } else if (rc == 0) {
2239 : : /* Once the connection is completed, we can submit queued requests */
2240 [ + - + - ]: 5541 : nvme_qpair_resubmit_requests(qpair, tqpair->num_entries);
2241 : 1670 : }
2242 : 1142071 : }
2243 : :
2244 : 73668553 : return reaped;
2245 : 212 : fail:
2246 : :
2247 : : /*
2248 : : * Since admin queues take the ctrlr_lock before entering this function,
2249 : : * we can call nvme_transport_ctrlr_disconnect_qpair. For other qpairs we need
2250 : : * to call the generic function which will take the lock for us.
2251 : : */
2252 [ # # ]: 212 : qpair->transport_failure_reason = SPDK_NVME_QPAIR_FAILURE_UNKNOWN;
2253 : :
2254 [ + + ]: 212 : if (nvme_qpair_is_admin_queue(qpair)) {
2255 : 128 : enum nvme_qpair_state state_prev = nvme_qpair_get_state(qpair);
2256 : :
2257 [ # # # # ]: 128 : nvme_transport_ctrlr_disconnect_qpair(qpair->ctrlr, qpair);
2258 : :
2259 [ + + + + : 128 : if (state_prev == NVME_QPAIR_CONNECTING && qpair->poll_status != NULL) {
# # # # ]
2260 : : /* Needed to free the poll_status */
2261 [ # # # # ]: 9 : nvme_tcp_ctrlr_connect_qpair_poll(qpair->ctrlr, qpair);
2262 : 0 : }
2263 : 0 : } else {
2264 : 84 : nvme_ctrlr_disconnect_qpair(qpair);
2265 : : }
2266 : 212 : return -ENXIO;
2267 : 1337795 : }
2268 : :
2269 : : static void
2270 : 35044552 : nvme_tcp_qpair_sock_cb(void *ctx, struct spdk_sock_group *group, struct spdk_sock *sock)
2271 : : {
2272 : 35044552 : struct spdk_nvme_qpair *qpair = ctx;
2273 [ # # # # ]: 35044552 : struct nvme_tcp_poll_group *pgroup = nvme_tcp_poll_group(qpair->poll_group);
2274 : : int32_t num_completions;
2275 : 35044552 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2276 : :
2277 [ - + + + : 35044552 : if (tqpair->needs_poll) {
# # # # ]
2278 [ + + # # : 1591031 : TAILQ_REMOVE(&pgroup->needs_poll, tqpair, link);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
2279 [ # # # # ]: 1591031 : tqpair->needs_poll = false;
2280 : 0 : }
2281 : :
2282 [ # # # # ]: 35044552 : num_completions = spdk_nvme_qpair_process_completions(qpair, pgroup->completions_per_qpair);
2283 : :
2284 [ + + + + : 35044552 : if (pgroup->num_completions >= 0 && num_completions >= 0) {
# # # # ]
2285 [ # # # # : 35044513 : pgroup->num_completions += num_completions;
# # ]
2286 [ # # # # : 35044513 : pgroup->stats.nvme_completions += num_completions;
# # ]
2287 : 0 : } else {
2288 [ # # # # ]: 39 : pgroup->num_completions = -ENXIO;
2289 : : }
2290 : 35044552 : }
2291 : :
2292 : : static int
2293 : 5597 : nvme_tcp_qpair_icreq_send(struct nvme_tcp_qpair *tqpair)
2294 : : {
2295 : : struct spdk_nvme_tcp_ic_req *ic_req;
2296 : : struct nvme_tcp_pdu *pdu;
2297 : : uint32_t timeout_in_sec;
2298 : :
2299 [ + - + - ]: 5597 : pdu = tqpair->send_pdu;
2300 [ + + + - : 5597 : memset(tqpair->send_pdu, 0, sizeof(*tqpair->send_pdu));
+ - ]
2301 [ + - + - ]: 5597 : ic_req = &pdu->hdr.ic_req;
2302 : :
2303 [ + - + - : 5597 : ic_req->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_IC_REQ;
+ - ]
2304 [ + - + - : 5597 : ic_req->common.hlen = ic_req->common.plen = sizeof(*ic_req);
+ - + - +
- + - ]
2305 [ + - + - ]: 5597 : ic_req->pfv = 0;
2306 [ + - + - ]: 5597 : ic_req->maxr2t = NVME_TCP_MAX_R2T_DEFAULT - 1;
2307 [ + - + - ]: 5597 : ic_req->hpda = NVME_TCP_HPDA_DEFAULT;
2308 : :
2309 [ + + + - : 5597 : ic_req->dgst.bits.hdgst_enable = tqpair->qpair.ctrlr->opts.header_digest;
+ - + - +
- + - + -
+ - + - +
- ]
2310 [ + + + - : 5597 : ic_req->dgst.bits.ddgst_enable = tqpair->qpair.ctrlr->opts.data_digest;
+ - + - +
- + - + -
+ - + - +
- ]
2311 : :
2312 : 5597 : nvme_tcp_qpair_write_pdu(tqpair, pdu, nvme_tcp_send_icreq_complete, tqpair);
2313 : :
2314 [ + + + - ]: 5597 : timeout_in_sec = tqpair->qpair.async ? ICREQ_TIMEOUT_ASYNC : ICREQ_TIMEOUT_SYNC;
2315 [ + - + - ]: 5597 : tqpair->icreq_timeout_tsc = spdk_get_ticks() + (timeout_in_sec * spdk_get_ticks_hz());
2316 : 5597 : return 0;
2317 : : }
2318 : :
2319 : : static int
2320 : 20182 : nvme_tcp_qpair_connect_sock(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
2321 : : {
2322 : 133 : struct sockaddr_storage dst_addr;
2323 : 133 : struct sockaddr_storage src_addr;
2324 : : int rc;
2325 : : struct nvme_tcp_qpair *tqpair;
2326 : : int family;
2327 : 20182 : long int port, src_port = 0;
2328 : : char *sock_impl_name;
2329 : 20182 : struct spdk_sock_impl_opts impl_opts = {};
2330 : 20182 : size_t impl_opts_size = sizeof(impl_opts);
2331 : 133 : struct spdk_sock_opts opts;
2332 : : struct nvme_tcp_ctrlr *tcp_ctrlr;
2333 : :
2334 : 20182 : tqpair = nvme_tcp_qpair(qpair);
2335 : :
2336 [ + - + - : 20182 : switch (ctrlr->trid.adrfam) {
+ - - +
- ]
2337 : 18506 : case SPDK_NVMF_ADRFAM_IPV4:
2338 : 20176 : family = AF_INET;
2339 : 20176 : break;
2340 : 0 : case SPDK_NVMF_ADRFAM_IPV6:
2341 : 0 : family = AF_INET6;
2342 : 0 : break;
2343 : 6 : default:
2344 [ # # # # : 6 : SPDK_ERRLOG("Unhandled ADRFAM %d\n", ctrlr->trid.adrfam);
# # ]
2345 : 6 : rc = -1;
2346 : 6 : return rc;
2347 : : }
2348 : :
2349 [ + + + + : 20176 : SPDK_DEBUGLOG(nvme, "adrfam %d ai_family %d\n", ctrlr->trid.adrfam, family);
+ - # # #
# # # ]
2350 : :
2351 [ + + ]: 20176 : memset(&dst_addr, 0, sizeof(dst_addr));
2352 : :
2353 [ + + + + : 20176 : SPDK_DEBUGLOG(nvme, "trsvcid is %s\n", ctrlr->trid.trsvcid);
+ - # # #
# ]
2354 [ + - + - : 20176 : rc = nvme_parse_addr(&dst_addr, family, ctrlr->trid.traddr, ctrlr->trid.trsvcid, &port);
+ - + - ]
2355 [ + + ]: 20176 : if (rc != 0) {
2356 : 6 : SPDK_ERRLOG("dst_addr nvme_parse_addr() failed\n");
2357 : 6 : return rc;
2358 : : }
2359 : :
2360 [ + + + + : 20170 : if (ctrlr->opts.src_addr[0] || ctrlr->opts.src_svcid[0]) {
+ - + - +
- + - + -
+ - + - +
- + - -
+ ]
2361 [ - + ]: 30 : memset(&src_addr, 0, sizeof(src_addr));
2362 : 60 : rc = nvme_parse_addr(&src_addr, family,
2363 [ + - # # : 30 : ctrlr->opts.src_addr[0] ? ctrlr->opts.src_addr : NULL,
# # # # #
# # # # #
# # ]
2364 [ + + # # : 30 : ctrlr->opts.src_svcid[0] ? ctrlr->opts.src_svcid : NULL,
# # # # #
# # # # #
# # ]
2365 : : &src_port);
2366 [ - + ]: 30 : if (rc != 0) {
2367 : 0 : SPDK_ERRLOG("src_addr nvme_parse_addr() failed\n");
2368 : 0 : return rc;
2369 : : }
2370 : 0 : }
2371 : :
2372 : 20170 : tcp_ctrlr = SPDK_CONTAINEROF(ctrlr, struct nvme_tcp_ctrlr, ctrlr);
2373 [ + + + - : 20170 : sock_impl_name = tcp_ctrlr->psk[0] ? "ssl" : NULL;
+ - + - ]
2374 [ + + + + : 20170 : SPDK_DEBUGLOG(nvme, "sock_impl_name is %s\n", sock_impl_name);
+ - ]
2375 : :
2376 [ + + ]: 20170 : if (sock_impl_name) {
2377 : 130 : spdk_sock_impl_get_opts(sock_impl_name, &impl_opts, &impl_opts_size);
2378 [ # # ]: 130 : impl_opts.tls_version = SPDK_TLS_VERSION_1_3;
2379 [ # # # # ]: 130 : impl_opts.psk_identity = tcp_ctrlr->psk_identity;
2380 [ # # # # ]: 130 : impl_opts.psk_key = tcp_ctrlr->psk;
2381 [ # # # # : 130 : impl_opts.psk_key_size = tcp_ctrlr->psk_size;
# # ]
2382 [ # # # # : 130 : impl_opts.tls_cipher_suites = tcp_ctrlr->tls_cipher_suite;
# # ]
2383 : 0 : }
2384 : 20170 : opts.opts_size = sizeof(opts);
2385 : 20170 : spdk_sock_get_default_opts(&opts);
2386 [ + - + - : 20170 : opts.priority = ctrlr->trid.priority;
+ - + - ]
2387 [ + - ]: 20170 : opts.zcopy = !nvme_qpair_is_admin_queue(qpair);
2388 [ + + + - : 20170 : opts.src_addr = ctrlr->opts.src_addr[0] ? ctrlr->opts.src_addr : NULL;
+ - + - +
- - + # #
# # + - ]
2389 [ + - ]: 20170 : opts.src_port = src_port;
2390 [ + + + - : 20170 : if (ctrlr->opts.transport_ack_timeout) {
+ - + - ]
2391 [ - + # # : 36 : opts.ack_timeout = 1ULL << ctrlr->opts.transport_ack_timeout;
# # # # #
# ]
2392 : 0 : }
2393 [ + + ]: 20170 : if (sock_impl_name) {
2394 [ # # ]: 130 : opts.impl_opts = &impl_opts;
2395 [ # # ]: 130 : opts.impl_opts_size = sizeof(impl_opts);
2396 : 0 : }
2397 [ + - + - : 20170 : tqpair->sock = spdk_sock_connect_ext(ctrlr->trid.traddr, port, sock_impl_name, &opts);
+ - + - ]
2398 [ + + + - : 20170 : if (!tqpair->sock) {
+ - ]
2399 [ # # # # ]: 14564 : SPDK_ERRLOG("sock connection error of tqpair=%p with addr=%s, port=%ld\n",
2400 : : tqpair, ctrlr->trid.traddr, port);
2401 : 14564 : rc = -1;
2402 : 14564 : return rc;
2403 : : }
2404 : :
2405 : 5606 : return 0;
2406 : 1670 : }
2407 : :
2408 : : static int
2409 : 8046034 : nvme_tcp_ctrlr_connect_qpair_poll(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
2410 : : {
2411 : : struct nvme_tcp_qpair *tqpair;
2412 : : int rc;
2413 : :
2414 : 8046034 : tqpair = nvme_tcp_qpair(qpair);
2415 : :
2416 : : /* Prevent this function from being called recursively, as it could lead to issues with
2417 : : * nvme_fabric_qpair_connect_poll() if the connect response is received in the recursive
2418 : : * call.
2419 : : */
2420 [ + + + - : 8046034 : if (tqpair->flags.in_connect_poll) {
+ + ]
2421 : 289496 : return -EAGAIN;
2422 : : }
2423 : :
2424 [ + - + - ]: 7756538 : tqpair->flags.in_connect_poll = 1;
2425 : :
2426 [ + + + + : 7756538 : switch (tqpair->state) {
- - + + +
- ]
2427 : 6260280 : case NVME_TCP_QPAIR_STATE_INVALID:
2428 : : case NVME_TCP_QPAIR_STATE_INITIALIZING:
2429 [ + + + - : 7364745 : if (spdk_get_ticks() > tqpair->icreq_timeout_tsc) {
- + ]
2430 : 0 : SPDK_ERRLOG("Failed to construct the tqpair=%p via correct icresp\n", tqpair);
2431 : 0 : rc = -ETIMEDOUT;
2432 : 0 : break;
2433 : : }
2434 : 7364745 : rc = -EAGAIN;
2435 : 7364745 : break;
2436 : 3909 : case NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_SEND:
2437 [ + - + - : 5579 : rc = nvme_fabric_qpair_connect_async(&tqpair->qpair, tqpair->num_entries + 1);
+ - + - ]
2438 [ - + ]: 5579 : if (rc < 0) {
2439 : 0 : SPDK_ERRLOG("Failed to send an NVMe-oF Fabric CONNECT command\n");
2440 : 0 : break;
2441 : : }
2442 [ + - + - ]: 5579 : tqpair->state = NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_POLL;
2443 : 5579 : rc = -EAGAIN;
2444 : 5579 : break;
2445 : 137558 : case NVME_TCP_QPAIR_STATE_FABRIC_CONNECT_POLL:
2446 [ + - ]: 155526 : rc = nvme_fabric_qpair_connect_poll(&tqpair->qpair);
2447 [ + + ]: 155526 : if (rc == 0) {
2448 [ + + ]: 5577 : if (nvme_fabric_qpair_auth_required(qpair)) {
2449 : 759 : rc = nvme_fabric_qpair_authenticate_async(qpair);
2450 [ + + ]: 759 : if (rc == 0) {
2451 [ # # # # ]: 748 : tqpair->state = NVME_TCP_QPAIR_STATE_AUTHENTICATING;
2452 : 748 : rc = -EAGAIN;
2453 : 0 : }
2454 : 0 : } else {
2455 [ + - + - ]: 4818 : tqpair->state = NVME_TCP_QPAIR_STATE_RUNNING;
2456 : 4818 : nvme_qpair_set_state(qpair, NVME_QPAIR_CONNECTED);
2457 : : }
2458 [ + + ]: 151619 : } else if (rc != -EAGAIN) {
2459 : 2 : SPDK_ERRLOG("Failed to poll NVMe-oF Fabric CONNECT command\n");
2460 : 0 : }
2461 : 155526 : break;
2462 : 230688 : case NVME_TCP_QPAIR_STATE_AUTHENTICATING:
2463 : 230688 : rc = nvme_fabric_qpair_authenticate_poll(qpair);
2464 [ + + ]: 230688 : if (rc == 0) {
2465 [ # # # # ]: 723 : tqpair->state = NVME_TCP_QPAIR_STATE_RUNNING;
2466 : 723 : nvme_qpair_set_state(qpair, NVME_QPAIR_CONNECTED);
2467 : 0 : }
2468 : 230688 : break;
2469 : 0 : case NVME_TCP_QPAIR_STATE_RUNNING:
2470 : 0 : rc = 0;
2471 : 0 : break;
2472 : 0 : default:
2473 [ # # ]: 0 : assert(false);
2474 : : rc = -EINVAL;
2475 : : break;
2476 : : }
2477 : :
2478 [ + - + - ]: 7756538 : tqpair->flags.in_connect_poll = 0;
2479 : 7756538 : return rc;
2480 : 1142071 : }
2481 : :
2482 : : static int
2483 : 20141 : nvme_tcp_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
2484 : : {
2485 : 20141 : int rc = 0;
2486 : : struct nvme_tcp_qpair *tqpair;
2487 : : struct nvme_tcp_poll_group *tgroup;
2488 : :
2489 : 20141 : tqpair = nvme_tcp_qpair(qpair);
2490 : :
2491 [ + + + - : 20141 : if (!tqpair->sock) {
+ - ]
2492 : 14598 : rc = nvme_tcp_qpair_connect_sock(ctrlr, qpair);
2493 [ + + ]: 14598 : if (rc < 0) {
2494 : 14547 : return rc;
2495 : : }
2496 : 0 : }
2497 : :
2498 [ + + + - : 5594 : if (qpair->poll_group) {
- + ]
2499 : 1052 : rc = nvme_poll_group_connect_qpair(qpair);
2500 [ - + ]: 1052 : if (rc) {
2501 : 0 : SPDK_ERRLOG("Unable to activate the tcp qpair.\n");
2502 : 0 : return rc;
2503 : : }
2504 [ # # # # ]: 1052 : tgroup = nvme_tcp_poll_group(qpair->poll_group);
2505 [ # # # # : 1052 : tqpair->stats = &tgroup->stats;
# # ]
2506 [ # # # # ]: 1052 : tqpair->shared_stats = true;
2507 : 0 : } else {
2508 : : /* When resetting a controller, we disconnect adminq and then reconnect. The stats
2509 : : * is not freed when disconnecting. So when reconnecting, don't allocate memory
2510 : : * again.
2511 : : */
2512 [ + + + - : 4542 : if (tqpair->stats == NULL) {
- + ]
2513 [ + - + - ]: 4491 : tqpair->stats = calloc(1, sizeof(*tqpair->stats));
2514 [ + + + - : 4491 : if (!tqpair->stats) {
- + ]
2515 : 0 : SPDK_ERRLOG("tcp stats memory allocation failed\n");
2516 : 0 : return -ENOMEM;
2517 : : }
2518 : 1670 : }
2519 : : }
2520 : :
2521 [ + - + - ]: 5594 : tqpair->maxr2t = NVME_TCP_MAX_R2T_DEFAULT;
2522 : : /* Explicitly set the state and recv_state of tqpair */
2523 [ + - + - ]: 5594 : tqpair->state = NVME_TCP_QPAIR_STATE_INVALID;
2524 [ + + + - : 5594 : if (tqpair->recv_state != NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY) {
+ - ]
2525 : 51 : nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
2526 : 0 : }
2527 : 5594 : rc = nvme_tcp_qpair_icreq_send(tqpair);
2528 [ + + ]: 5594 : if (rc != 0) {
2529 : 0 : SPDK_ERRLOG("Unable to connect the tqpair\n");
2530 : 0 : return rc;
2531 : : }
2532 : :
2533 : 5594 : return rc;
2534 : 1670 : }
2535 : :
2536 : : static struct spdk_nvme_qpair *
2537 : 5581 : nvme_tcp_ctrlr_create_qpair(struct spdk_nvme_ctrlr *ctrlr,
2538 : : uint16_t qid, uint32_t qsize,
2539 : : enum spdk_nvme_qprio qprio,
2540 : : uint32_t num_requests, bool async)
2541 : : {
2542 : : struct nvme_tcp_qpair *tqpair;
2543 : : struct spdk_nvme_qpair *qpair;
2544 : : int rc;
2545 : :
2546 [ + + ]: 5581 : if (qsize < SPDK_NVME_QUEUE_MIN_ENTRIES) {
2547 : 9 : SPDK_ERRLOG("Failed to create qpair with size %u. Minimum queue size is %d.\n",
2548 : : qsize, SPDK_NVME_QUEUE_MIN_ENTRIES);
2549 : 9 : return NULL;
2550 : : }
2551 : :
2552 : 5572 : tqpair = calloc(1, sizeof(struct nvme_tcp_qpair));
2553 [ + + ]: 5572 : if (!tqpair) {
2554 : 0 : SPDK_ERRLOG("failed to get create tqpair\n");
2555 : 0 : return NULL;
2556 : : }
2557 : :
2558 : : /* Set num_entries one less than queue size. According to NVMe
2559 : : * and NVMe-oF specs we can not submit queue size requests,
2560 : : * one slot shall always remain empty.
2561 : : */
2562 [ - + - + ]: 5572 : tqpair->num_entries = qsize - 1;
2563 [ - + ]: 5572 : qpair = &tqpair->qpair;
2564 [ - + ]: 5572 : rc = nvme_qpair_init(qpair, qid, ctrlr, qprio, num_requests, async);
2565 [ - + ]: 5572 : if (rc != 0) {
2566 : 0 : free(tqpair);
2567 : 0 : return NULL;
2568 : : }
2569 : :
2570 : 5572 : rc = nvme_tcp_alloc_reqs(tqpair);
2571 [ - + ]: 5572 : if (rc) {
2572 : 0 : nvme_tcp_ctrlr_delete_io_qpair(ctrlr, qpair);
2573 : 0 : return NULL;
2574 : : }
2575 : :
2576 : : /* spdk_nvme_qpair_get_optimal_poll_group needs socket information.
2577 : : * So create the socket first when creating a qpair. */
2578 : 5572 : rc = nvme_tcp_qpair_connect_sock(ctrlr, qpair);
2579 [ + + ]: 5572 : if (rc) {
2580 : 20 : nvme_tcp_ctrlr_delete_io_qpair(ctrlr, qpair);
2581 : 20 : return NULL;
2582 : : }
2583 : :
2584 : 5552 : return qpair;
2585 : 1670 : }
2586 : :
2587 : : static struct spdk_nvme_qpair *
2588 : 3359 : nvme_tcp_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
2589 : : const struct spdk_nvme_io_qpair_opts *opts)
2590 : : {
2591 [ + - + - : 4198 : return nvme_tcp_ctrlr_create_qpair(ctrlr, qid, opts->io_queue_size, opts->qprio,
+ - + - ]
2592 [ + + + - : 3359 : opts->io_queue_requests, opts->async_mode);
+ - + - +
- ]
2593 : : }
2594 : :
2595 : : static int
2596 : 62 : nvme_tcp_generate_tls_credentials(struct nvme_tcp_ctrlr *tctrlr)
2597 : : {
2598 [ # # ]: 62 : struct spdk_nvme_ctrlr *ctrlr = &tctrlr->ctrlr;
2599 : : int rc;
2600 : 62 : uint8_t psk_retained[SPDK_TLS_PSK_MAX_LEN] = {};
2601 : 62 : uint8_t psk_configured[SPDK_TLS_PSK_MAX_LEN] = {};
2602 : 62 : uint8_t pskbuf[SPDK_TLS_PSK_MAX_LEN + 1] = {};
2603 : : uint8_t tls_cipher_suite;
2604 : 0 : uint8_t psk_retained_hash;
2605 : 0 : uint64_t psk_configured_size;
2606 : :
2607 [ # # # # : 62 : rc = spdk_key_get_key(ctrlr->opts.tls_psk, pskbuf, SPDK_TLS_PSK_MAX_LEN);
# # ]
2608 [ + + ]: 62 : if (rc < 0) {
2609 [ # # # # : 3 : SPDK_ERRLOG("Failed to obtain key '%s': %s\n",
# # # # ]
2610 : : spdk_key_get_name(ctrlr->opts.tls_psk), spdk_strerror(-rc));
2611 : 3 : goto finish;
2612 : : }
2613 : :
2614 : 59 : rc = nvme_tcp_parse_interchange_psk(pskbuf, psk_configured, sizeof(psk_configured),
2615 : : &psk_configured_size, &psk_retained_hash);
2616 [ - + ]: 59 : if (rc < 0) {
2617 : 0 : SPDK_ERRLOG("Failed to parse PSK interchange!\n");
2618 : 0 : goto finish;
2619 : : }
2620 : :
2621 : : /* The Base64 string encodes the configured PSK (32 or 48 bytes binary).
2622 : : * This check also ensures that psk_configured_size is smaller than
2623 : : * psk_retained buffer size. */
2624 [ + + ]: 59 : if (psk_configured_size == SHA256_DIGEST_LENGTH) {
2625 : 41 : tls_cipher_suite = NVME_TCP_CIPHER_AES_128_GCM_SHA256;
2626 [ # # # # ]: 41 : tctrlr->tls_cipher_suite = "TLS_AES_128_GCM_SHA256";
2627 [ + - ]: 18 : } else if (psk_configured_size == SHA384_DIGEST_LENGTH) {
2628 : 18 : tls_cipher_suite = NVME_TCP_CIPHER_AES_256_GCM_SHA384;
2629 [ # # # # ]: 18 : tctrlr->tls_cipher_suite = "TLS_AES_256_GCM_SHA384";
2630 : 0 : } else {
2631 : 0 : SPDK_ERRLOG("Unrecognized cipher suite!\n");
2632 : 0 : rc = -ENOTSUP;
2633 : 0 : goto finish;
2634 : : }
2635 : :
2636 [ # # ]: 59 : rc = nvme_tcp_generate_psk_identity(tctrlr->psk_identity, sizeof(tctrlr->psk_identity),
2637 [ # # # # : 59 : ctrlr->opts.hostnqn, ctrlr->trid.subnqn,
# # # # ]
2638 : 0 : tls_cipher_suite);
2639 [ - + ]: 59 : if (rc) {
2640 : 0 : SPDK_ERRLOG("could not generate PSK identity\n");
2641 : 0 : goto finish;
2642 : : }
2643 : :
2644 : : /* No hash indicates that Configured PSK must be used as Retained PSK. */
2645 [ + + ]: 59 : if (psk_retained_hash == NVME_TCP_HASH_ALGORITHM_NONE) {
2646 [ - + # # ]: 21 : assert(psk_configured_size < sizeof(psk_retained));
2647 [ - + - + ]: 21 : memcpy(psk_retained, psk_configured, psk_configured_size);
2648 : 21 : rc = psk_configured_size;
2649 : 0 : } else {
2650 : : /* Derive retained PSK. */
2651 [ # # # # ]: 38 : rc = nvme_tcp_derive_retained_psk(psk_configured, psk_configured_size, ctrlr->opts.hostnqn,
2652 : 0 : psk_retained, sizeof(psk_retained), psk_retained_hash);
2653 [ - + ]: 38 : if (rc < 0) {
2654 : 0 : SPDK_ERRLOG("Unable to derive retained PSK!\n");
2655 : 0 : goto finish;
2656 : : }
2657 : : }
2658 : :
2659 [ # # # # ]: 59 : rc = nvme_tcp_derive_tls_psk(psk_retained, rc, tctrlr->psk_identity, tctrlr->psk,
2660 : 0 : sizeof(tctrlr->psk), tls_cipher_suite);
2661 [ - + ]: 59 : if (rc < 0) {
2662 : 0 : SPDK_ERRLOG("Could not generate TLS PSK!\n");
2663 : 0 : goto finish;
2664 : : }
2665 : :
2666 [ # # # # ]: 59 : tctrlr->psk_size = rc;
2667 : 59 : rc = 0;
2668 : 62 : finish:
2669 : 62 : spdk_memset_s(psk_configured, sizeof(psk_configured), 0, sizeof(psk_configured));
2670 : 62 : spdk_memset_s(pskbuf, sizeof(pskbuf), 0, sizeof(pskbuf));
2671 : :
2672 : 62 : return rc;
2673 : : }
2674 : :
2675 : : /* We have to use the typedef in the function declaration to appease astyle. */
2676 : : typedef struct spdk_nvme_ctrlr spdk_nvme_ctrlr_t;
2677 : :
2678 : : static spdk_nvme_ctrlr_t *
2679 : 2225 : nvme_tcp_ctrlr_construct(const struct spdk_nvme_transport_id *trid,
2680 : : const struct spdk_nvme_ctrlr_opts *opts,
2681 : : void *devhandle)
2682 : : {
2683 : : struct nvme_tcp_ctrlr *tctrlr;
2684 : : struct nvme_tcp_qpair *tqpair;
2685 : : int rc;
2686 : :
2687 : 2225 : tctrlr = calloc(1, sizeof(*tctrlr));
2688 [ + + ]: 2225 : if (tctrlr == NULL) {
2689 : 0 : SPDK_ERRLOG("could not allocate ctrlr\n");
2690 : 0 : return NULL;
2691 : : }
2692 : :
2693 [ + - + - ]: 2225 : tctrlr->ctrlr.opts = *opts;
2694 [ + - + - ]: 2225 : tctrlr->ctrlr.trid = *trid;
2695 : :
2696 [ + + + - : 2225 : if (opts->tls_psk != NULL) {
+ - ]
2697 : 62 : rc = nvme_tcp_generate_tls_credentials(tctrlr);
2698 [ + + ]: 62 : if (rc != 0) {
2699 : 3 : free(tctrlr);
2700 : 3 : return NULL;
2701 : : }
2702 : 0 : }
2703 : :
2704 [ + + + - : 2222 : if (opts->transport_ack_timeout > NVME_TCP_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT) {
+ - ]
2705 : 15 : SPDK_NOTICELOG("transport_ack_timeout exceeds max value %d, use max value\n",
2706 : : NVME_TCP_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT);
2707 [ # # # # : 15 : tctrlr->ctrlr.opts.transport_ack_timeout = NVME_TCP_CTRLR_MAX_TRANSPORT_ACK_TIMEOUT;
# # # # ]
2708 : 0 : }
2709 : :
2710 [ + - ]: 2222 : rc = nvme_ctrlr_construct(&tctrlr->ctrlr);
2711 [ - + ]: 2222 : if (rc != 0) {
2712 : 0 : free(tctrlr);
2713 : 0 : return NULL;
2714 : : }
2715 : :
2716 : : /* Sequence might be used not only for data digest offload purposes but
2717 : : * to handle a potential COPY operation appended as the result of translation. */
2718 [ + - + - : 2222 : tctrlr->ctrlr.flags |= SPDK_NVME_CTRLR_ACCEL_SEQUENCE_SUPPORTED;
+ - ]
2719 [ + - + - : 3062 : tctrlr->ctrlr.adminq = nvme_tcp_ctrlr_create_qpair(&tctrlr->ctrlr, 0,
+ - + - ]
2720 [ + - + - : 2222 : tctrlr->ctrlr.opts.admin_queue_size, 0,
+ - + - ]
2721 [ + - + - : 2222 : tctrlr->ctrlr.opts.admin_queue_size, true);
+ - + - ]
2722 [ + + + - : 2222 : if (!tctrlr->ctrlr.adminq) {
+ - + - ]
2723 : 23 : SPDK_ERRLOG("failed to create admin qpair\n");
2724 [ # # ]: 23 : nvme_tcp_ctrlr_destruct(&tctrlr->ctrlr);
2725 : 23 : return NULL;
2726 : : }
2727 : :
2728 [ + - + - : 2199 : tqpair = nvme_tcp_qpair(tctrlr->ctrlr.adminq);
+ - ]
2729 [ + - + - : 2199 : tctrlr->ctrlr.numa.id_valid = 1;
+ - ]
2730 [ + - + - : 2199 : tctrlr->ctrlr.numa.id = spdk_sock_get_numa_id(tqpair->sock);
+ - + - +
- ]
2731 : :
2732 [ + + - + ]: 2199 : if (nvme_ctrlr_add_process(&tctrlr->ctrlr, 0) != 0) {
2733 : 0 : SPDK_ERRLOG("nvme_ctrlr_add_process() failed\n");
2734 [ # # ]: 0 : nvme_ctrlr_destruct(&tctrlr->ctrlr);
2735 : 0 : return NULL;
2736 : : }
2737 : :
2738 [ - + ]: 2199 : return &tctrlr->ctrlr;
2739 : 835 : }
2740 : :
2741 : : static uint32_t
2742 : 2181 : nvme_tcp_ctrlr_get_max_xfer_size(struct spdk_nvme_ctrlr *ctrlr)
2743 : : {
2744 : : /* TCP transport doesn't limit maximum IO transfer size. */
2745 : 2181 : return UINT32_MAX;
2746 : : }
2747 : :
2748 : : static uint16_t
2749 : 2181 : nvme_tcp_ctrlr_get_max_sges(struct spdk_nvme_ctrlr *ctrlr)
2750 : : {
2751 : 2181 : return NVME_TCP_MAX_SGL_DESCRIPTORS;
2752 : : }
2753 : :
2754 : : static int
2755 : 429160 : nvme_tcp_qpair_iterate_requests(struct spdk_nvme_qpair *qpair,
2756 : : int (*iter_fn)(struct nvme_request *req, void *arg),
2757 : : void *arg)
2758 : : {
2759 : 429160 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2760 : : struct nvme_tcp_req *tcp_req, *tmp;
2761 : : int rc;
2762 : :
2763 [ - + # # ]: 429160 : assert(iter_fn != NULL);
2764 : :
2765 [ + + # # : 25379062 : TAILQ_FOREACH_SAFE(tcp_req, &tqpair->outstanding_reqs, link, tmp) {
# # # # #
# # # # #
# # ]
2766 [ - + # # : 24949925 : assert(tcp_req->req != NULL);
# # # # ]
2767 : :
2768 [ # # # # : 24949925 : rc = iter_fn(tcp_req->req, arg);
# # # # ]
2769 [ + + ]: 24949925 : if (rc != 0) {
2770 : 23 : return rc;
2771 : : }
2772 : 0 : }
2773 : :
2774 : 429137 : return 0;
2775 : 0 : }
2776 : :
2777 : : static int
2778 : 18 : nvme_tcp_qpair_authenticate(struct spdk_nvme_qpair *qpair)
2779 : : {
2780 : 18 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2781 : : int rc;
2782 : :
2783 : : /* If the qpair is still connecting, it'll be forced to authenticate later on */
2784 [ - + # # : 18 : if (tqpair->state < NVME_TCP_QPAIR_STATE_RUNNING) {
# # ]
2785 : 0 : return 0;
2786 [ - + # # : 18 : } else if (tqpair->state != NVME_TCP_QPAIR_STATE_RUNNING) {
# # ]
2787 : 0 : return -ENOTCONN;
2788 : : }
2789 : :
2790 : 18 : rc = nvme_fabric_qpair_authenticate_async(qpair);
2791 [ + + ]: 18 : if (rc == 0) {
2792 : 14 : nvme_qpair_set_state(qpair, NVME_QPAIR_CONNECTING);
2793 [ # # # # ]: 14 : tqpair->state = NVME_TCP_QPAIR_STATE_AUTHENTICATING;
2794 : 0 : }
2795 : :
2796 : 18 : return rc;
2797 : 0 : }
2798 : :
2799 : : static void
2800 : 2590 : nvme_tcp_admin_qpair_abort_aers(struct spdk_nvme_qpair *qpair)
2801 : : {
2802 : : struct nvme_tcp_req *tcp_req, *tmp;
2803 : 2590 : struct spdk_nvme_cpl cpl = {};
2804 : 2590 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2805 : :
2806 [ + - + - ]: 2590 : cpl.status.sc = SPDK_NVME_SC_ABORTED_SQ_DELETION;
2807 [ + - + - ]: 2590 : cpl.status.sct = SPDK_NVME_SCT_GENERIC;
2808 : :
2809 [ + + + - : 11026 : TAILQ_FOREACH_SAFE(tcp_req, &tqpair->outstanding_reqs, link, tmp) {
+ - + + +
- + - + -
+ + ]
2810 [ + + + - : 8436 : assert(tcp_req->req != NULL);
+ - # # ]
2811 [ + + + - : 8436 : if (tcp_req->req->cmd.opc != SPDK_NVME_OPC_ASYNC_EVENT_REQUEST) {
+ - + - -
+ ]
2812 : 2 : continue;
2813 : : }
2814 : :
2815 : 8434 : nvme_tcp_req_complete(tcp_req, tqpair, &cpl, false);
2816 : 3340 : }
2817 : 2590 : }
2818 : :
2819 : : static struct spdk_nvme_transport_poll_group *
2820 : 946 : nvme_tcp_poll_group_create(void)
2821 : : {
2822 : 946 : struct nvme_tcp_poll_group *group = calloc(1, sizeof(*group));
2823 : :
2824 [ - + ]: 946 : if (group == NULL) {
2825 : 0 : SPDK_ERRLOG("Unable to allocate poll group.\n");
2826 : 0 : return NULL;
2827 : : }
2828 : :
2829 [ # # # # : 946 : TAILQ_INIT(&group->needs_poll);
# # # # #
# # # # #
# # ]
2830 : :
2831 [ # # # # ]: 946 : group->sock_group = spdk_sock_group_create(group);
2832 [ - + # # : 946 : if (group->sock_group == NULL) {
# # ]
2833 : 0 : free(group);
2834 : 0 : SPDK_ERRLOG("Unable to allocate sock group.\n");
2835 : 0 : return NULL;
2836 : : }
2837 : :
2838 [ # # ]: 946 : return &group->group;
2839 : 0 : }
2840 : :
2841 : : static struct spdk_nvme_transport_poll_group *
2842 : 0 : nvme_tcp_qpair_get_optimal_poll_group(struct spdk_nvme_qpair *qpair)
2843 : : {
2844 : 0 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2845 : 0 : struct spdk_sock_group *group = NULL;
2846 : : int rc;
2847 : :
2848 [ # # # # ]: 0 : rc = spdk_sock_get_optimal_sock_group(tqpair->sock, &group, NULL);
2849 [ # # # # ]: 0 : if (!rc && group != NULL) {
2850 : 0 : return spdk_sock_group_get_ctx(group);
2851 : : }
2852 : :
2853 : 0 : return NULL;
2854 : 0 : }
2855 : :
2856 : : static int
2857 : 1052 : nvme_tcp_poll_group_connect_qpair(struct spdk_nvme_qpair *qpair)
2858 : : {
2859 [ # # # # ]: 1052 : struct nvme_tcp_poll_group *group = nvme_tcp_poll_group(qpair->poll_group);
2860 : 1052 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2861 : :
2862 [ - + # # : 1052 : if (spdk_sock_group_add_sock(group->sock_group, tqpair->sock, nvme_tcp_qpair_sock_cb, qpair)) {
# # # # #
# ]
2863 : 0 : return -EPROTO;
2864 : : }
2865 : 1052 : return 0;
2866 : 0 : }
2867 : :
2868 : : static int
2869 : 1052 : nvme_tcp_poll_group_disconnect_qpair(struct spdk_nvme_qpair *qpair)
2870 : : {
2871 [ # # # # ]: 1052 : struct nvme_tcp_poll_group *group = nvme_tcp_poll_group(qpair->poll_group);
2872 : 1052 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2873 : :
2874 [ - + + + : 1052 : if (tqpair->needs_poll) {
# # # # ]
2875 [ - + # # : 8 : TAILQ_REMOVE(&group->needs_poll, tqpair, link);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
2876 [ # # # # ]: 8 : tqpair->needs_poll = false;
2877 : 0 : }
2878 : :
2879 [ + - + - : 1052 : if (tqpair->sock && group->sock_group) {
# # # # #
# # # ]
2880 [ - + # # : 1052 : if (spdk_sock_group_remove_sock(group->sock_group, tqpair->sock)) {
# # # # #
# ]
2881 : 0 : return -EPROTO;
2882 : : }
2883 : 0 : }
2884 : 1052 : return 0;
2885 : 0 : }
2886 : :
2887 : : static int
2888 : 1052 : nvme_tcp_poll_group_add(struct spdk_nvme_transport_poll_group *tgroup,
2889 : : struct spdk_nvme_qpair *qpair)
2890 : : {
2891 : 1052 : struct nvme_tcp_qpair *tqpair = nvme_tcp_qpair(qpair);
2892 : 1052 : struct nvme_tcp_poll_group *group = nvme_tcp_poll_group(tgroup);
2893 : :
2894 : : /* disconnected qpairs won't have a sock to add. */
2895 [ - + ]: 1052 : if (nvme_qpair_get_state(qpair) >= NVME_QPAIR_CONNECTED) {
2896 [ # # # # : 0 : if (spdk_sock_group_add_sock(group->sock_group, tqpair->sock, nvme_tcp_qpair_sock_cb, qpair)) {
# # # # #
# ]
2897 : 0 : return -EPROTO;
2898 : : }
2899 : 0 : }
2900 : :
2901 : 1052 : return 0;
2902 : 0 : }
2903 : :
2904 : : static int
2905 : 1052 : nvme_tcp_poll_group_remove(struct spdk_nvme_transport_poll_group *tgroup,
2906 : : struct spdk_nvme_qpair *qpair)
2907 : : {
2908 : : struct nvme_tcp_qpair *tqpair;
2909 : : struct nvme_tcp_poll_group *group;
2910 : :
2911 [ - + # # : 1052 : assert(qpair->poll_group_tailq_head == &tgroup->disconnected_qpairs);
# # # # #
# ]
2912 : :
2913 : 1052 : tqpair = nvme_tcp_qpair(qpair);
2914 : 1052 : group = nvme_tcp_poll_group(tgroup);
2915 : :
2916 [ - + - + : 1052 : assert(tqpair->shared_stats == true);
# # # # #
# ]
2917 [ # # # # ]: 1052 : tqpair->stats = &g_dummy_stats;
2918 : :
2919 [ - + + + : 1052 : if (tqpair->needs_poll) {
# # # # ]
2920 [ - + # # : 2 : TAILQ_REMOVE(&group->needs_poll, tqpair, link);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
2921 [ # # # # ]: 2 : tqpair->needs_poll = false;
2922 : 0 : }
2923 : :
2924 : 1052 : return 0;
2925 : : }
2926 : :
2927 : : static int64_t
2928 : 348224343 : nvme_tcp_poll_group_process_completions(struct spdk_nvme_transport_poll_group *tgroup,
2929 : : uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb)
2930 : : {
2931 : 348224343 : struct nvme_tcp_poll_group *group = nvme_tcp_poll_group(tgroup);
2932 : : struct spdk_nvme_qpair *qpair, *tmp_qpair;
2933 : : struct nvme_tcp_qpair *tqpair, *tmp_tqpair;
2934 : : int num_events;
2935 : :
2936 [ # # # # ]: 348224343 : group->completions_per_qpair = completions_per_qpair;
2937 [ # # # # ]: 348224343 : group->num_completions = 0;
2938 [ # # # # ]: 348224343 : group->stats.polls++;
2939 : :
2940 [ # # # # ]: 348224343 : num_events = spdk_sock_group_poll(group->sock_group);
2941 : :
2942 [ + + # # : 352175349 : STAILQ_FOREACH_SAFE(qpair, &tgroup->disconnected_qpairs, poll_group_stailq, tmp_qpair) {
# # # # #
# # # # #
# # ]
2943 : 3951006 : tqpair = nvme_tcp_qpair(qpair);
2944 [ + + ]: 3951006 : if (nvme_qpair_get_state(qpair) == NVME_QPAIR_DISCONNECTING) {
2945 [ + + # # : 901 : if (TAILQ_EMPTY(&tqpair->outstanding_reqs)) {
# # # # ]
2946 : 898 : nvme_transport_ctrlr_disconnect_qpair_done(qpair);
2947 : 0 : }
2948 : 0 : }
2949 : : /* Wait until the qpair transitions to the DISCONNECTED state, otherwise user might
2950 : : * want to free it from disconnect_qpair_cb, while it's not fully disconnected (and
2951 : : * might still have outstanding requests) */
2952 [ + + ]: 3951006 : if (nvme_qpair_get_state(qpair) == NVME_QPAIR_DISCONNECTED) {
2953 [ # # # # : 3951003 : disconnected_qpair_cb(qpair, tgroup->group->ctx);
# # # # #
# # # ]
2954 : 0 : }
2955 : 0 : }
2956 : :
2957 : : /* If any qpairs were marked as needing to be polled due to an asynchronous write completion
2958 : : * and they weren't polled as a consequence of calling spdk_sock_group_poll above, poll them now. */
2959 [ + + # # : 348860349 : TAILQ_FOREACH_SAFE(tqpair, &group->needs_poll, link, tmp_tqpair) {
# # # # #
# # # # #
# # ]
2960 [ # # # # : 636006 : nvme_tcp_qpair_sock_cb(&tqpair->qpair, group->sock_group, tqpair->sock);
# # # # #
# ]
2961 : 0 : }
2962 : :
2963 [ - + ]: 348224343 : if (spdk_unlikely(num_events < 0)) {
2964 : 0 : return num_events;
2965 : : }
2966 : :
2967 [ # # # # : 348224343 : group->stats.idle_polls += !num_events;
# # ]
2968 [ # # # # : 348224343 : group->stats.socket_completions += num_events;
# # ]
2969 : :
2970 [ # # # # ]: 348224343 : return group->num_completions;
2971 : 0 : }
2972 : :
2973 : : static int
2974 : 946 : nvme_tcp_poll_group_destroy(struct spdk_nvme_transport_poll_group *tgroup)
2975 : : {
2976 : : int rc;
2977 : 946 : struct nvme_tcp_poll_group *group = nvme_tcp_poll_group(tgroup);
2978 : :
2979 [ + - - + : 946 : if (!STAILQ_EMPTY(&tgroup->connected_qpairs) || !STAILQ_EMPTY(&tgroup->disconnected_qpairs)) {
# # # # #
# # # # #
# # ]
2980 : 0 : return -EBUSY;
2981 : : }
2982 : :
2983 [ # # ]: 946 : rc = spdk_sock_group_close(&group->sock_group);
2984 [ - + ]: 946 : if (rc != 0) {
2985 : 0 : SPDK_ERRLOG("Failed to close the sock group for a tcp poll group.\n");
2986 [ # # ]: 0 : assert(false);
2987 : : }
2988 : :
2989 : 946 : free(tgroup);
2990 : :
2991 : 946 : return 0;
2992 : 0 : }
2993 : :
2994 : : static int
2995 : 15 : nvme_tcp_poll_group_get_stats(struct spdk_nvme_transport_poll_group *tgroup,
2996 : : struct spdk_nvme_transport_poll_group_stat **_stats)
2997 : : {
2998 : : struct nvme_tcp_poll_group *group;
2999 : : struct spdk_nvme_transport_poll_group_stat *stats;
3000 : :
3001 [ + + + + ]: 15 : if (tgroup == NULL || _stats == NULL) {
3002 : 6 : SPDK_ERRLOG("Invalid stats or group pointer\n");
3003 : 6 : return -EINVAL;
3004 : : }
3005 : :
3006 : 9 : group = nvme_tcp_poll_group(tgroup);
3007 : :
3008 : 9 : stats = calloc(1, sizeof(*stats));
3009 [ - + ]: 9 : if (!stats) {
3010 : 0 : SPDK_ERRLOG("Can't allocate memory for TCP stats\n");
3011 : 0 : return -ENOMEM;
3012 : : }
3013 [ # # # # ]: 9 : stats->trtype = SPDK_NVME_TRANSPORT_TCP;
3014 [ - + - + : 9 : memcpy(&stats->tcp, &group->stats, sizeof(group->stats));
# # # # #
# ]
3015 : :
3016 [ # # ]: 9 : *_stats = stats;
3017 : :
3018 : 9 : return 0;
3019 : 0 : }
3020 : :
3021 : : static void
3022 : 9 : nvme_tcp_poll_group_free_stats(struct spdk_nvme_transport_poll_group *tgroup,
3023 : : struct spdk_nvme_transport_poll_group_stat *stats)
3024 : : {
3025 : 9 : free(stats);
3026 : 9 : }
3027 : :
3028 : : static int
3029 : 3480 : nvme_tcp_ctrlr_get_memory_domains(const struct spdk_nvme_ctrlr *ctrlr,
3030 : : struct spdk_memory_domain **domains, int array_size)
3031 : : {
3032 [ + + + - ]: 3480 : if (domains && array_size > 0) {
3033 [ # # # # ]: 221 : domains[0] = spdk_memory_domain_get_system_domain();
3034 : 0 : }
3035 : :
3036 : 3480 : return 1;
3037 : : }
3038 : :
3039 : : const struct spdk_nvme_transport_ops tcp_ops = {
3040 : : .name = "TCP",
3041 : : .type = SPDK_NVME_TRANSPORT_TCP,
3042 : : .ctrlr_construct = nvme_tcp_ctrlr_construct,
3043 : : .ctrlr_scan = nvme_fabric_ctrlr_scan,
3044 : : .ctrlr_destruct = nvme_tcp_ctrlr_destruct,
3045 : : .ctrlr_enable = nvme_tcp_ctrlr_enable,
3046 : :
3047 : : .ctrlr_set_reg_4 = nvme_fabric_ctrlr_set_reg_4,
3048 : : .ctrlr_set_reg_8 = nvme_fabric_ctrlr_set_reg_8,
3049 : : .ctrlr_get_reg_4 = nvme_fabric_ctrlr_get_reg_4,
3050 : : .ctrlr_get_reg_8 = nvme_fabric_ctrlr_get_reg_8,
3051 : : .ctrlr_set_reg_4_async = nvme_fabric_ctrlr_set_reg_4_async,
3052 : : .ctrlr_set_reg_8_async = nvme_fabric_ctrlr_set_reg_8_async,
3053 : : .ctrlr_get_reg_4_async = nvme_fabric_ctrlr_get_reg_4_async,
3054 : : .ctrlr_get_reg_8_async = nvme_fabric_ctrlr_get_reg_8_async,
3055 : :
3056 : : .ctrlr_get_max_xfer_size = nvme_tcp_ctrlr_get_max_xfer_size,
3057 : : .ctrlr_get_max_sges = nvme_tcp_ctrlr_get_max_sges,
3058 : :
3059 : : .ctrlr_create_io_qpair = nvme_tcp_ctrlr_create_io_qpair,
3060 : : .ctrlr_delete_io_qpair = nvme_tcp_ctrlr_delete_io_qpair,
3061 : : .ctrlr_connect_qpair = nvme_tcp_ctrlr_connect_qpair,
3062 : : .ctrlr_disconnect_qpair = nvme_tcp_ctrlr_disconnect_qpair,
3063 : :
3064 : : .ctrlr_get_memory_domains = nvme_tcp_ctrlr_get_memory_domains,
3065 : :
3066 : : .qpair_abort_reqs = nvme_tcp_qpair_abort_reqs,
3067 : : .qpair_reset = nvme_tcp_qpair_reset,
3068 : : .qpair_submit_request = nvme_tcp_qpair_submit_request,
3069 : : .qpair_process_completions = nvme_tcp_qpair_process_completions,
3070 : : .qpair_iterate_requests = nvme_tcp_qpair_iterate_requests,
3071 : : .qpair_authenticate = nvme_tcp_qpair_authenticate,
3072 : : .admin_qpair_abort_aers = nvme_tcp_admin_qpair_abort_aers,
3073 : :
3074 : : .poll_group_create = nvme_tcp_poll_group_create,
3075 : : .qpair_get_optimal_poll_group = nvme_tcp_qpair_get_optimal_poll_group,
3076 : : .poll_group_connect_qpair = nvme_tcp_poll_group_connect_qpair,
3077 : : .poll_group_disconnect_qpair = nvme_tcp_poll_group_disconnect_qpair,
3078 : : .poll_group_add = nvme_tcp_poll_group_add,
3079 : : .poll_group_remove = nvme_tcp_poll_group_remove,
3080 : : .poll_group_process_completions = nvme_tcp_poll_group_process_completions,
3081 : : .poll_group_destroy = nvme_tcp_poll_group_destroy,
3082 : : .poll_group_get_stats = nvme_tcp_poll_group_get_stats,
3083 : : .poll_group_free_stats = nvme_tcp_poll_group_free_stats,
3084 : : };
3085 : :
3086 : 2583 : SPDK_NVME_TRANSPORT_REGISTER(tcp, &tcp_ops);
3087 : :
3088 : : static void
3089 : 1967 : nvme_tcp_trace(void)
3090 : : {
3091 : 1967 : struct spdk_trace_tpoint_opts opts[] = {
3092 : : {
3093 : : "NVME_TCP_SUBMIT", TRACE_NVME_TCP_SUBMIT,
3094 : : OWNER_TYPE_NVME_TCP_QP, OBJECT_NVME_TCP_REQ, 1,
3095 : : { { "ctx", SPDK_TRACE_ARG_TYPE_PTR, 8 },
3096 : : { "cid", SPDK_TRACE_ARG_TYPE_INT, 4 },
3097 : : { "opc", SPDK_TRACE_ARG_TYPE_INT, 4 },
3098 : : { "dw10", SPDK_TRACE_ARG_TYPE_PTR, 4 },
3099 : : { "dw11", SPDK_TRACE_ARG_TYPE_PTR, 4 },
3100 : : { "dw12", SPDK_TRACE_ARG_TYPE_PTR, 4 },
3101 : : { "qd", SPDK_TRACE_ARG_TYPE_INT, 4 }
3102 : : }
3103 : : },
3104 : : {
3105 : : "NVME_TCP_COMPLETE", TRACE_NVME_TCP_COMPLETE,
3106 : : OWNER_TYPE_NVME_TCP_QP, OBJECT_NVME_TCP_REQ, 0,
3107 : : { { "ctx", SPDK_TRACE_ARG_TYPE_PTR, 8 },
3108 : : { "cid", SPDK_TRACE_ARG_TYPE_INT, 4 },
3109 : : { "cpl", SPDK_TRACE_ARG_TYPE_PTR, 4 },
3110 : : { "qd", SPDK_TRACE_ARG_TYPE_INT, 4 }
3111 : : }
3112 : : },
3113 : : };
3114 : :
3115 : 1967 : spdk_trace_register_object(OBJECT_NVME_TCP_REQ, 'p');
3116 : 1967 : spdk_trace_register_owner_type(OWNER_TYPE_NVME_TCP_QP, 'q');
3117 : 1967 : spdk_trace_register_description_ext(opts, SPDK_COUNTOF(opts));
3118 : :
3119 : 1967 : spdk_trace_tpoint_register_relation(TRACE_SOCK_REQ_QUEUE, OBJECT_NVME_TCP_REQ, 0);
3120 : 1967 : spdk_trace_tpoint_register_relation(TRACE_SOCK_REQ_PEND, OBJECT_NVME_TCP_REQ, 0);
3121 : 1967 : spdk_trace_tpoint_register_relation(TRACE_SOCK_REQ_COMPLETE, OBJECT_NVME_TCP_REQ, 0);
3122 : 1967 : }
3123 : 2583 : SPDK_TRACE_REGISTER_FN(nvme_tcp_trace, "nvme_tcp", TRACE_GROUP_NVME_TCP)
|