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) 2019, 2020 Mellanox Technologies LTD. All rights reserved.
4 : : * Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5 : : */
6 : :
7 : : #include "spdk/accel.h"
8 : : #include "spdk/stdinc.h"
9 : : #include "spdk/crc32.h"
10 : : #include "spdk/endian.h"
11 : : #include "spdk/assert.h"
12 : : #include "spdk/thread.h"
13 : : #include "spdk/nvmf_transport.h"
14 : : #include "spdk/string.h"
15 : : #include "spdk/trace.h"
16 : : #include "spdk/util.h"
17 : : #include "spdk/log.h"
18 : : #include "spdk/keyring.h"
19 : :
20 : : #include "spdk_internal/assert.h"
21 : : #include "spdk_internal/nvme_tcp.h"
22 : : #include "spdk_internal/sock.h"
23 : :
24 : : #include "nvmf_internal.h"
25 : : #include "transport.h"
26 : :
27 : : #include "spdk_internal/trace_defs.h"
28 : :
29 : : #define NVMF_TCP_MAX_ACCEPT_SOCK_ONE_TIME 16
30 : : #define SPDK_NVMF_TCP_DEFAULT_MAX_SOCK_PRIORITY 16
31 : : #define SPDK_NVMF_TCP_DEFAULT_SOCK_PRIORITY 0
32 : : #define SPDK_NVMF_TCP_DEFAULT_CONTROL_MSG_NUM 32
33 : : #define SPDK_NVMF_TCP_DEFAULT_SUCCESS_OPTIMIZATION true
34 : :
35 : : #define SPDK_NVMF_TCP_MIN_IO_QUEUE_DEPTH 2
36 : : #define SPDK_NVMF_TCP_MAX_IO_QUEUE_DEPTH 65535
37 : : #define SPDK_NVMF_TCP_MIN_ADMIN_QUEUE_DEPTH 2
38 : : #define SPDK_NVMF_TCP_MAX_ADMIN_QUEUE_DEPTH 4096
39 : :
40 : : #define SPDK_NVMF_TCP_DEFAULT_MAX_IO_QUEUE_DEPTH 128
41 : : #define SPDK_NVMF_TCP_DEFAULT_MAX_ADMIN_QUEUE_DEPTH 128
42 : : #define SPDK_NVMF_TCP_DEFAULT_MAX_QPAIRS_PER_CTRLR 128
43 : : #define SPDK_NVMF_TCP_DEFAULT_IN_CAPSULE_DATA_SIZE 4096
44 : : #define SPDK_NVMF_TCP_DEFAULT_MAX_IO_SIZE 131072
45 : : #define SPDK_NVMF_TCP_DEFAULT_IO_UNIT_SIZE 131072
46 : : #define SPDK_NVMF_TCP_DEFAULT_NUM_SHARED_BUFFERS 511
47 : : #define SPDK_NVMF_TCP_DEFAULT_BUFFER_CACHE_SIZE UINT32_MAX
48 : : #define SPDK_NVMF_TCP_DEFAULT_DIF_INSERT_OR_STRIP false
49 : : #define SPDK_NVMF_TCP_DEFAULT_ABORT_TIMEOUT_SEC 1
50 : :
51 : : #define TCP_PSK_INVALID_PERMISSIONS 0177
52 : :
53 : : const struct spdk_nvmf_transport_ops spdk_nvmf_transport_tcp;
54 : : static bool g_tls_log = false;
55 : :
56 : : /* spdk nvmf related structure */
57 : : enum spdk_nvmf_tcp_req_state {
58 : :
59 : : /* The request is not currently in use */
60 : : TCP_REQUEST_STATE_FREE = 0,
61 : :
62 : : /* Initial state when request first received */
63 : : TCP_REQUEST_STATE_NEW = 1,
64 : :
65 : : /* The request is queued until a data buffer is available. */
66 : : TCP_REQUEST_STATE_NEED_BUFFER = 2,
67 : :
68 : : /* The request is waiting for zcopy_start to finish */
69 : : TCP_REQUEST_STATE_AWAITING_ZCOPY_START = 3,
70 : :
71 : : /* The request has received a zero-copy buffer */
72 : : TCP_REQUEST_STATE_ZCOPY_START_COMPLETED = 4,
73 : :
74 : : /* The request is currently transferring data from the host to the controller. */
75 : : TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER = 5,
76 : :
77 : : /* The request is waiting for the R2T send acknowledgement. */
78 : : TCP_REQUEST_STATE_AWAITING_R2T_ACK = 6,
79 : :
80 : : /* The request is ready to execute at the block device */
81 : : TCP_REQUEST_STATE_READY_TO_EXECUTE = 7,
82 : :
83 : : /* The request is currently executing at the block device */
84 : : TCP_REQUEST_STATE_EXECUTING = 8,
85 : :
86 : : /* The request is waiting for zcopy buffers to be committed */
87 : : TCP_REQUEST_STATE_AWAITING_ZCOPY_COMMIT = 9,
88 : :
89 : : /* The request finished executing at the block device */
90 : : TCP_REQUEST_STATE_EXECUTED = 10,
91 : :
92 : : /* The request is ready to send a completion */
93 : : TCP_REQUEST_STATE_READY_TO_COMPLETE = 11,
94 : :
95 : : /* The request is currently transferring final pdus from the controller to the host. */
96 : : TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST = 12,
97 : :
98 : : /* The request is waiting for zcopy buffers to be released (without committing) */
99 : : TCP_REQUEST_STATE_AWAITING_ZCOPY_RELEASE = 13,
100 : :
101 : : /* The request completed and can be marked free. */
102 : : TCP_REQUEST_STATE_COMPLETED = 14,
103 : :
104 : : /* Terminator */
105 : : TCP_REQUEST_NUM_STATES,
106 : : };
107 : :
108 : : static const char *spdk_nvmf_tcp_term_req_fes_str[] = {
109 : : "Invalid PDU Header Field",
110 : : "PDU Sequence Error",
111 : : "Header Digiest Error",
112 : : "Data Transfer Out of Range",
113 : : "R2T Limit Exceeded",
114 : : "Unsupported parameter",
115 : : };
116 : :
117 : 1869 : SPDK_TRACE_REGISTER_FN(nvmf_tcp_trace, "nvmf_tcp", TRACE_GROUP_NVMF_TCP)
118 : : {
119 : 904 : spdk_trace_register_owner_type(OWNER_TYPE_NVMF_TCP, 't');
120 : 904 : spdk_trace_register_object(OBJECT_NVMF_TCP_IO, 'r');
121 : 904 : spdk_trace_register_description("TCP_REQ_NEW",
122 : : TRACE_TCP_REQUEST_STATE_NEW,
123 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 1,
124 : : SPDK_TRACE_ARG_TYPE_INT, "qd");
125 : 904 : spdk_trace_register_description("TCP_REQ_NEED_BUFFER",
126 : : TRACE_TCP_REQUEST_STATE_NEED_BUFFER,
127 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
128 : : SPDK_TRACE_ARG_TYPE_INT, "");
129 : 904 : spdk_trace_register_description("TCP_REQ_WAIT_ZCPY_START",
130 : : TRACE_TCP_REQUEST_STATE_AWAIT_ZCOPY_START,
131 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
132 : : SPDK_TRACE_ARG_TYPE_INT, "");
133 : 904 : spdk_trace_register_description("TCP_REQ_ZCPY_START_CPL",
134 : : TRACE_TCP_REQUEST_STATE_ZCOPY_START_COMPLETED,
135 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
136 : : SPDK_TRACE_ARG_TYPE_INT, "");
137 : 904 : spdk_trace_register_description("TCP_REQ_TX_H_TO_C",
138 : : TRACE_TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER,
139 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
140 : : SPDK_TRACE_ARG_TYPE_INT, "");
141 : 904 : spdk_trace_register_description("TCP_REQ_RDY_TO_EXECUTE",
142 : : TRACE_TCP_REQUEST_STATE_READY_TO_EXECUTE,
143 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
144 : : SPDK_TRACE_ARG_TYPE_INT, "");
145 : 904 : spdk_trace_register_description("TCP_REQ_EXECUTING",
146 : : TRACE_TCP_REQUEST_STATE_EXECUTING,
147 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
148 : : SPDK_TRACE_ARG_TYPE_INT, "");
149 : 904 : spdk_trace_register_description("TCP_REQ_WAIT_ZCPY_CMT",
150 : : TRACE_TCP_REQUEST_STATE_AWAIT_ZCOPY_COMMIT,
151 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
152 : : SPDK_TRACE_ARG_TYPE_INT, "");
153 : 904 : spdk_trace_register_description("TCP_REQ_EXECUTED",
154 : : TRACE_TCP_REQUEST_STATE_EXECUTED,
155 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
156 : : SPDK_TRACE_ARG_TYPE_INT, "");
157 : 904 : spdk_trace_register_description("TCP_REQ_RDY_TO_COMPLETE",
158 : : TRACE_TCP_REQUEST_STATE_READY_TO_COMPLETE,
159 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
160 : : SPDK_TRACE_ARG_TYPE_INT, "");
161 : 904 : spdk_trace_register_description("TCP_REQ_TRANSFER_C2H",
162 : : TRACE_TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST,
163 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
164 : : SPDK_TRACE_ARG_TYPE_INT, "");
165 : 904 : spdk_trace_register_description("TCP_REQ_AWAIT_ZCPY_RLS",
166 : : TRACE_TCP_REQUEST_STATE_AWAIT_ZCOPY_RELEASE,
167 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
168 : : SPDK_TRACE_ARG_TYPE_INT, "");
169 : 904 : spdk_trace_register_description("TCP_REQ_COMPLETED",
170 : : TRACE_TCP_REQUEST_STATE_COMPLETED,
171 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
172 : : SPDK_TRACE_ARG_TYPE_INT, "qd");
173 : 904 : spdk_trace_register_description("TCP_READ_DONE",
174 : : TRACE_TCP_READ_FROM_SOCKET_DONE,
175 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
176 : : SPDK_TRACE_ARG_TYPE_INT, "");
177 : 904 : spdk_trace_register_description("TCP_REQ_AWAIT_R2T_ACK",
178 : : TRACE_TCP_REQUEST_STATE_AWAIT_R2T_ACK,
179 : : OWNER_TYPE_NVMF_TCP, OBJECT_NVMF_TCP_IO, 0,
180 : : SPDK_TRACE_ARG_TYPE_INT, "");
181 : :
182 : 904 : spdk_trace_register_description("TCP_QP_CREATE", TRACE_TCP_QP_CREATE,
183 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
184 : : SPDK_TRACE_ARG_TYPE_INT, "");
185 : 904 : spdk_trace_register_description("TCP_QP_SOCK_INIT", TRACE_TCP_QP_SOCK_INIT,
186 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
187 : : SPDK_TRACE_ARG_TYPE_INT, "");
188 : 904 : spdk_trace_register_description("TCP_QP_STATE_CHANGE", TRACE_TCP_QP_STATE_CHANGE,
189 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
190 : : SPDK_TRACE_ARG_TYPE_INT, "state");
191 : 904 : spdk_trace_register_description("TCP_QP_DISCONNECT", TRACE_TCP_QP_DISCONNECT,
192 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
193 : : SPDK_TRACE_ARG_TYPE_INT, "");
194 : 904 : spdk_trace_register_description("TCP_QP_DESTROY", TRACE_TCP_QP_DESTROY,
195 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
196 : : SPDK_TRACE_ARG_TYPE_INT, "");
197 : 904 : spdk_trace_register_description("TCP_QP_ABORT_REQ", TRACE_TCP_QP_ABORT_REQ,
198 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
199 : : SPDK_TRACE_ARG_TYPE_INT, "");
200 : 904 : spdk_trace_register_description("TCP_QP_RCV_STATE_CHANGE", TRACE_TCP_QP_RCV_STATE_CHANGE,
201 : : OWNER_TYPE_NVMF_TCP, OBJECT_NONE, 0,
202 : : SPDK_TRACE_ARG_TYPE_INT, "state");
203 : :
204 : 904 : spdk_trace_tpoint_register_relation(TRACE_BDEV_IO_START, OBJECT_NVMF_TCP_IO, 1);
205 : 904 : spdk_trace_tpoint_register_relation(TRACE_BDEV_IO_DONE, OBJECT_NVMF_TCP_IO, 0);
206 : 904 : spdk_trace_tpoint_register_relation(TRACE_SOCK_REQ_QUEUE, OBJECT_NVMF_TCP_IO, 0);
207 : 904 : spdk_trace_tpoint_register_relation(TRACE_SOCK_REQ_PEND, OBJECT_NVMF_TCP_IO, 0);
208 : 904 : spdk_trace_tpoint_register_relation(TRACE_SOCK_REQ_COMPLETE, OBJECT_NVMF_TCP_IO, 0);
209 : 904 : }
210 : :
211 : : struct spdk_nvmf_tcp_req {
212 : : struct spdk_nvmf_request req;
213 : : struct spdk_nvme_cpl rsp;
214 : : struct spdk_nvme_cmd cmd;
215 : :
216 : : /* A PDU that can be used for sending responses. This is
217 : : * not the incoming PDU! */
218 : : struct nvme_tcp_pdu *pdu;
219 : :
220 : : /* In-capsule data buffer */
221 : : uint8_t *buf;
222 : :
223 : : struct spdk_nvmf_tcp_req *fused_pair;
224 : :
225 : : /*
226 : : * The PDU for a request may be used multiple times in serial over
227 : : * the request's lifetime. For example, first to send an R2T, then
228 : : * to send a completion. To catch mistakes where the PDU is used
229 : : * twice at the same time, add a debug flag here for init/fini.
230 : : */
231 : : bool pdu_in_use;
232 : : bool has_in_capsule_data;
233 : : bool fused_failed;
234 : :
235 : : /* transfer_tag */
236 : : uint16_t ttag;
237 : :
238 : : enum spdk_nvmf_tcp_req_state state;
239 : :
240 : : /*
241 : : * h2c_offset is used when we receive the h2c_data PDU.
242 : : */
243 : : uint32_t h2c_offset;
244 : :
245 : : STAILQ_ENTRY(spdk_nvmf_tcp_req) link;
246 : : TAILQ_ENTRY(spdk_nvmf_tcp_req) state_link;
247 : : };
248 : :
249 : : struct spdk_nvmf_tcp_qpair {
250 : : struct spdk_nvmf_qpair qpair;
251 : : struct spdk_nvmf_tcp_poll_group *group;
252 : : struct spdk_sock *sock;
253 : :
254 : : enum nvme_tcp_pdu_recv_state recv_state;
255 : : enum nvme_tcp_qpair_state state;
256 : :
257 : : /* PDU being actively received */
258 : : struct nvme_tcp_pdu *pdu_in_progress;
259 : :
260 : : struct spdk_nvmf_tcp_req *fused_first;
261 : :
262 : : /* Queues to track the requests in all states */
263 : : TAILQ_HEAD(, spdk_nvmf_tcp_req) tcp_req_working_queue;
264 : : TAILQ_HEAD(, spdk_nvmf_tcp_req) tcp_req_free_queue;
265 : : SLIST_HEAD(, nvme_tcp_pdu) tcp_pdu_free_queue;
266 : : /* Number of working pdus */
267 : : uint32_t tcp_pdu_working_count;
268 : :
269 : : /* Number of requests in each state */
270 : : uint32_t state_cntr[TCP_REQUEST_NUM_STATES];
271 : :
272 : : uint8_t cpda;
273 : :
274 : : bool host_hdgst_enable;
275 : : bool host_ddgst_enable;
276 : :
277 : : /* This is a spare PDU used for sending special management
278 : : * operations. Primarily, this is used for the initial
279 : : * connection response and c2h termination request. */
280 : : struct nvme_tcp_pdu *mgmt_pdu;
281 : :
282 : : /* Arrays of in-capsule buffers, requests, and pdus.
283 : : * Each array is 'resource_count' number of elements */
284 : : void *bufs;
285 : : struct spdk_nvmf_tcp_req *reqs;
286 : : struct nvme_tcp_pdu *pdus;
287 : : uint32_t resource_count;
288 : : uint32_t recv_buf_size;
289 : :
290 : : struct spdk_nvmf_tcp_port *port;
291 : :
292 : : /* IP address */
293 : : char initiator_addr[SPDK_NVMF_TRADDR_MAX_LEN];
294 : : char target_addr[SPDK_NVMF_TRADDR_MAX_LEN];
295 : :
296 : : /* IP port */
297 : : uint16_t initiator_port;
298 : : uint16_t target_port;
299 : :
300 : : /* Wait until the host terminates the connection (e.g. after sending C2HTermReq) */
301 : : bool wait_terminate;
302 : :
303 : : /* Timer used to destroy qpair after detecting transport error issue if initiator does
304 : : * not close the connection.
305 : : */
306 : : struct spdk_poller *timeout_poller;
307 : :
308 : : spdk_nvmf_transport_qpair_fini_cb fini_cb_fn;
309 : : void *fini_cb_arg;
310 : :
311 : : TAILQ_ENTRY(spdk_nvmf_tcp_qpair) link;
312 : : };
313 : :
314 : : struct spdk_nvmf_tcp_control_msg {
315 : : STAILQ_ENTRY(spdk_nvmf_tcp_control_msg) link;
316 : : };
317 : :
318 : : struct spdk_nvmf_tcp_control_msg_list {
319 : : void *msg_buf;
320 : : STAILQ_HEAD(, spdk_nvmf_tcp_control_msg) free_msgs;
321 : : };
322 : :
323 : : struct spdk_nvmf_tcp_poll_group {
324 : : struct spdk_nvmf_transport_poll_group group;
325 : : struct spdk_sock_group *sock_group;
326 : :
327 : : TAILQ_HEAD(, spdk_nvmf_tcp_qpair) qpairs;
328 : : TAILQ_HEAD(, spdk_nvmf_tcp_qpair) await_req;
329 : :
330 : : struct spdk_io_channel *accel_channel;
331 : : struct spdk_nvmf_tcp_control_msg_list *control_msg_list;
332 : :
333 : : TAILQ_ENTRY(spdk_nvmf_tcp_poll_group) link;
334 : : };
335 : :
336 : : struct spdk_nvmf_tcp_port {
337 : : const struct spdk_nvme_transport_id *trid;
338 : : struct spdk_sock *listen_sock;
339 : : struct spdk_nvmf_transport *transport;
340 : : TAILQ_ENTRY(spdk_nvmf_tcp_port) link;
341 : : };
342 : :
343 : : struct tcp_transport_opts {
344 : : bool c2h_success;
345 : : uint16_t control_msg_num;
346 : : uint32_t sock_priority;
347 : : };
348 : :
349 : : struct tcp_psk_entry {
350 : : char hostnqn[SPDK_NVMF_NQN_MAX_LEN + 1];
351 : : char subnqn[SPDK_NVMF_NQN_MAX_LEN + 1];
352 : : char pskid[NVMF_PSK_IDENTITY_LEN];
353 : : uint8_t psk[SPDK_TLS_PSK_MAX_LEN];
354 : : struct spdk_key *key;
355 : :
356 : : /* Original path saved to emit SPDK configuration via "save_config". */
357 : : char psk_path[PATH_MAX];
358 : : uint32_t psk_size;
359 : : enum nvme_tcp_cipher_suite tls_cipher_suite;
360 : : TAILQ_ENTRY(tcp_psk_entry) link;
361 : : };
362 : :
363 : : struct spdk_nvmf_tcp_transport {
364 : : struct spdk_nvmf_transport transport;
365 : : struct tcp_transport_opts tcp_opts;
366 : : uint32_t ack_timeout;
367 : :
368 : : struct spdk_nvmf_tcp_poll_group *next_pg;
369 : :
370 : : struct spdk_poller *accept_poller;
371 : : struct spdk_sock_group *listen_sock_group;
372 : :
373 : : TAILQ_HEAD(, spdk_nvmf_tcp_port) ports;
374 : : TAILQ_HEAD(, spdk_nvmf_tcp_poll_group) poll_groups;
375 : :
376 : : TAILQ_HEAD(, tcp_psk_entry) psks;
377 : : };
378 : :
379 : : static const struct spdk_json_object_decoder tcp_transport_opts_decoder[] = {
380 : : {
381 : : "c2h_success", offsetof(struct tcp_transport_opts, c2h_success),
382 : : spdk_json_decode_bool, true
383 : : },
384 : : {
385 : : "control_msg_num", offsetof(struct tcp_transport_opts, control_msg_num),
386 : : spdk_json_decode_uint16, true
387 : : },
388 : : {
389 : : "sock_priority", offsetof(struct tcp_transport_opts, sock_priority),
390 : : spdk_json_decode_uint32, true
391 : : },
392 : : };
393 : :
394 : : static bool nvmf_tcp_req_process(struct spdk_nvmf_tcp_transport *ttransport,
395 : : struct spdk_nvmf_tcp_req *tcp_req);
396 : : static void nvmf_tcp_poll_group_destroy(struct spdk_nvmf_transport_poll_group *group);
397 : :
398 : : static void _nvmf_tcp_send_c2h_data(struct spdk_nvmf_tcp_qpair *tqpair,
399 : : struct spdk_nvmf_tcp_req *tcp_req);
400 : :
401 : : static inline void
402 : 195877254 : nvmf_tcp_req_set_state(struct spdk_nvmf_tcp_req *tcp_req,
403 : : enum spdk_nvmf_tcp_req_state state)
404 : : {
405 : : struct spdk_nvmf_qpair *qpair;
406 : : struct spdk_nvmf_tcp_qpair *tqpair;
407 : :
408 : 195877254 : qpair = tcp_req->req.qpair;
409 : 195877254 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
410 : :
411 [ - + ]: 195877254 : assert(tqpair->state_cntr[tcp_req->state] > 0);
412 : 195877254 : tqpair->state_cntr[tcp_req->state]--;
413 : 195877254 : tqpair->state_cntr[state]++;
414 : :
415 : 195877254 : tcp_req->state = state;
416 : 195877254 : }
417 : :
418 : : static inline struct nvme_tcp_pdu *
419 : 31730433 : nvmf_tcp_req_pdu_init(struct spdk_nvmf_tcp_req *tcp_req)
420 : : {
421 [ - + - + ]: 31730433 : assert(tcp_req->pdu_in_use == false);
422 : :
423 [ - + ]: 31730433 : memset(tcp_req->pdu, 0, sizeof(*tcp_req->pdu));
424 : 31730433 : tcp_req->pdu->qpair = SPDK_CONTAINEROF(tcp_req->req.qpair, struct spdk_nvmf_tcp_qpair, qpair);
425 : :
426 : 31730433 : return tcp_req->pdu;
427 : : }
428 : :
429 : : static struct spdk_nvmf_tcp_req *
430 : 21651713 : nvmf_tcp_req_get(struct spdk_nvmf_tcp_qpair *tqpair)
431 : : {
432 : : struct spdk_nvmf_tcp_req *tcp_req;
433 : :
434 : 21651713 : tcp_req = TAILQ_FIRST(&tqpair->tcp_req_free_queue);
435 [ + + ]: 21651713 : if (spdk_unlikely(!tcp_req)) {
436 : 545282 : return NULL;
437 : : }
438 : :
439 [ - + ]: 21106431 : memset(&tcp_req->rsp, 0, sizeof(tcp_req->rsp));
440 : 21106431 : tcp_req->h2c_offset = 0;
441 : 21106431 : tcp_req->has_in_capsule_data = false;
442 : 21106431 : tcp_req->req.dif_enabled = false;
443 : 21106431 : tcp_req->req.zcopy_phase = NVMF_ZCOPY_PHASE_NONE;
444 : :
445 [ + + ]: 21106431 : TAILQ_REMOVE(&tqpair->tcp_req_free_queue, tcp_req, state_link);
446 : 21106431 : TAILQ_INSERT_TAIL(&tqpair->tcp_req_working_queue, tcp_req, state_link);
447 : 21106431 : tqpair->qpair.queue_depth++;
448 : 21106431 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_NEW);
449 : 21106431 : return tcp_req;
450 : : }
451 : :
452 : : static inline void
453 : 21106428 : nvmf_tcp_req_put(struct spdk_nvmf_tcp_qpair *tqpair, struct spdk_nvmf_tcp_req *tcp_req)
454 : : {
455 [ - + - + ]: 21106428 : assert(!tcp_req->pdu_in_use);
456 : :
457 [ + + ]: 21106428 : TAILQ_REMOVE(&tqpair->tcp_req_working_queue, tcp_req, state_link);
458 : 21106428 : TAILQ_INSERT_TAIL(&tqpair->tcp_req_free_queue, tcp_req, state_link);
459 : 21106428 : tqpair->qpair.queue_depth--;
460 : 21106428 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_FREE);
461 : 21106428 : }
462 : :
463 : : static void
464 : 3 : nvmf_tcp_req_get_buffers(struct spdk_nvmf_request *req)
465 : : {
466 : : struct spdk_nvmf_tcp_req *tcp_req;
467 : : struct spdk_nvmf_transport *transport;
468 : : struct spdk_nvmf_tcp_transport *ttransport;
469 : :
470 : 3 : tcp_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_tcp_req, req);
471 : 3 : transport = req->qpair->transport;
472 : 3 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
473 : :
474 : 3 : nvmf_tcp_req_process(ttransport, tcp_req);
475 : 3 : }
476 : :
477 : : static void
478 : 20230600 : nvmf_tcp_request_free(void *cb_arg)
479 : : {
480 : : struct spdk_nvmf_tcp_transport *ttransport;
481 : 20230600 : struct spdk_nvmf_tcp_req *tcp_req = cb_arg;
482 : :
483 [ - + ]: 20230600 : assert(tcp_req != NULL);
484 : :
485 [ - + - + ]: 20230600 : SPDK_DEBUGLOG(nvmf_tcp, "tcp_req=%p will be freed\n", tcp_req);
486 : 20230600 : ttransport = SPDK_CONTAINEROF(tcp_req->req.qpair->transport,
487 : : struct spdk_nvmf_tcp_transport, transport);
488 : 20230600 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_COMPLETED);
489 : 20230600 : nvmf_tcp_req_process(ttransport, tcp_req);
490 : 20230600 : }
491 : :
492 : : static int
493 : 7327 : nvmf_tcp_req_free(struct spdk_nvmf_request *req)
494 : : {
495 : 7327 : struct spdk_nvmf_tcp_req *tcp_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_tcp_req, req);
496 : :
497 : 7327 : nvmf_tcp_request_free(tcp_req);
498 : :
499 : 7327 : return 0;
500 : : }
501 : :
502 : : static void
503 : 73962 : nvmf_tcp_drain_state_queue(struct spdk_nvmf_tcp_qpair *tqpair,
504 : : enum spdk_nvmf_tcp_req_state state)
505 : : {
506 : : struct spdk_nvmf_tcp_req *tcp_req, *req_tmp;
507 : :
508 [ - + ]: 73962 : assert(state != TCP_REQUEST_STATE_FREE);
509 [ + + ]: 77081 : TAILQ_FOREACH_SAFE(tcp_req, &tqpair->tcp_req_working_queue, state_link, req_tmp) {
510 [ + + ]: 3119 : if (state == tcp_req->state) {
511 : 2470 : nvmf_tcp_request_free(tcp_req);
512 : : }
513 : : }
514 : 73962 : }
515 : :
516 : : static inline void
517 : 0 : nvmf_tcp_request_get_buffers_abort(struct spdk_nvmf_tcp_req *tcp_req)
518 : : {
519 [ # # ]: 0 : assert(tcp_req->state == TCP_REQUEST_STATE_NEED_BUFFER);
520 [ # # ]: 0 : if (!nvmf_request_get_buffers_abort(&tcp_req->req)) {
521 : 0 : SPDK_ERRLOG("Failed to abort tcp_req=%p\n", tcp_req);
522 : 0 : assert(0 && "Should never happen");
523 : : }
524 : 0 : }
525 : :
526 : : static void
527 : 12327 : nvmf_tcp_cleanup_all_states(struct spdk_nvmf_tcp_qpair *tqpair)
528 : : {
529 : : struct spdk_nvmf_tcp_req *tcp_req, *req_tmp;
530 : :
531 : 12327 : nvmf_tcp_drain_state_queue(tqpair, TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST);
532 : 12327 : nvmf_tcp_drain_state_queue(tqpair, TCP_REQUEST_STATE_NEW);
533 : :
534 : : /* Wipe the requests waiting for buffer from the iobuf waiting list */
535 [ + + ]: 12484 : TAILQ_FOREACH_SAFE(tcp_req, &tqpair->tcp_req_working_queue, state_link, req_tmp) {
536 [ - + ]: 157 : if (tcp_req->state == TCP_REQUEST_STATE_NEED_BUFFER) {
537 : 0 : nvmf_tcp_request_get_buffers_abort(tcp_req);
538 : : }
539 : : }
540 : :
541 : 12327 : nvmf_tcp_drain_state_queue(tqpair, TCP_REQUEST_STATE_NEED_BUFFER);
542 : 12327 : nvmf_tcp_drain_state_queue(tqpair, TCP_REQUEST_STATE_EXECUTING);
543 : 12327 : nvmf_tcp_drain_state_queue(tqpair, TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER);
544 : 12327 : nvmf_tcp_drain_state_queue(tqpair, TCP_REQUEST_STATE_AWAITING_R2T_ACK);
545 : 12327 : }
546 : :
547 : : static void
548 : 0 : nvmf_tcp_dump_qpair_req_contents(struct spdk_nvmf_tcp_qpair *tqpair)
549 : : {
550 : : int i;
551 : : struct spdk_nvmf_tcp_req *tcp_req;
552 : :
553 : 0 : SPDK_ERRLOG("Dumping contents of queue pair (QID %d)\n", tqpair->qpair.qid);
554 [ # # ]: 0 : for (i = 1; i < TCP_REQUEST_NUM_STATES; i++) {
555 : 0 : SPDK_ERRLOG("\tNum of requests in state[%d] = %u\n", i, tqpair->state_cntr[i]);
556 [ # # ]: 0 : TAILQ_FOREACH(tcp_req, &tqpair->tcp_req_working_queue, state_link) {
557 [ # # ]: 0 : if ((int)tcp_req->state == i) {
558 : 0 : SPDK_ERRLOG("\t\tRequest Data From Pool: %d\n", tcp_req->req.data_from_pool);
559 : 0 : SPDK_ERRLOG("\t\tRequest opcode: %d\n", tcp_req->req.cmd->nvmf_cmd.opcode);
560 : : }
561 : : }
562 : : }
563 : 0 : }
564 : :
565 : : static void
566 : 12327 : _nvmf_tcp_qpair_destroy(void *_tqpair)
567 : : {
568 : 12327 : struct spdk_nvmf_tcp_qpair *tqpair = _tqpair;
569 : 12327 : spdk_nvmf_transport_qpair_fini_cb cb_fn = tqpair->fini_cb_fn;
570 : 12327 : void *cb_arg = tqpair->fini_cb_arg;
571 : 12327 : int err = 0;
572 : :
573 [ + + + + ]: 12327 : spdk_trace_record(TRACE_TCP_QP_DESTROY, tqpair->qpair.trace_id, 0, 0);
574 : :
575 [ - + - + ]: 12327 : SPDK_DEBUGLOG(nvmf_tcp, "enter\n");
576 : :
577 : 12327 : err = spdk_sock_close(&tqpair->sock);
578 [ - + ]: 12327 : assert(err == 0);
579 : 12327 : nvmf_tcp_cleanup_all_states(tqpair);
580 : :
581 [ - + ]: 12327 : if (tqpair->state_cntr[TCP_REQUEST_STATE_FREE] != tqpair->resource_count) {
582 : 0 : SPDK_ERRLOG("tqpair(%p) free tcp request num is %u but should be %u\n", tqpair,
583 : : tqpair->state_cntr[TCP_REQUEST_STATE_FREE],
584 : : tqpair->resource_count);
585 : 0 : err++;
586 : : }
587 : :
588 [ - + ]: 12327 : if (err > 0) {
589 : 0 : nvmf_tcp_dump_qpair_req_contents(tqpair);
590 : : }
591 : :
592 : : /* The timeout poller might still be registered here if we close the qpair before host
593 : : * terminates the connection.
594 : : */
595 : 12327 : spdk_poller_unregister(&tqpair->timeout_poller);
596 : 12327 : spdk_dma_free(tqpair->pdus);
597 : 12327 : free(tqpair->reqs);
598 : 12327 : spdk_free(tqpair->bufs);
599 : 12327 : spdk_trace_unregister_owner(tqpair->qpair.trace_id);
600 : 12327 : free(tqpair);
601 : :
602 [ + + ]: 12327 : if (cb_fn != NULL) {
603 : 12324 : cb_fn(cb_arg);
604 : : }
605 : :
606 [ - + - + ]: 12327 : SPDK_DEBUGLOG(nvmf_tcp, "Leave\n");
607 : 12327 : }
608 : :
609 : : static void
610 : 12327 : nvmf_tcp_qpair_destroy(struct spdk_nvmf_tcp_qpair *tqpair)
611 : : {
612 : : /* Delay the destruction to make sure it isn't performed from the context of a sock
613 : : * callback. Otherwise, spdk_sock_close() might not abort pending requests, causing their
614 : : * completions to be executed after the qpair is freed. (Note: this fixed issue #2471.)
615 : : */
616 : 12327 : spdk_thread_send_msg(spdk_get_thread(), _nvmf_tcp_qpair_destroy, tqpair);
617 : 12327 : }
618 : :
619 : : static void
620 : 125 : nvmf_tcp_dump_opts(struct spdk_nvmf_transport *transport, struct spdk_json_write_ctx *w)
621 : : {
622 : : struct spdk_nvmf_tcp_transport *ttransport;
623 [ - + ]: 125 : assert(w != NULL);
624 : :
625 : 125 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
626 [ - + ]: 125 : spdk_json_write_named_bool(w, "c2h_success", ttransport->tcp_opts.c2h_success);
627 : 125 : spdk_json_write_named_uint32(w, "sock_priority", ttransport->tcp_opts.sock_priority);
628 : 125 : }
629 : :
630 : : static void
631 : 58 : nvmf_tcp_free_psk_entry(struct tcp_psk_entry *entry)
632 : : {
633 [ - + ]: 58 : if (entry == NULL) {
634 : 0 : return;
635 : : }
636 : :
637 : 58 : spdk_memset_s(entry->psk, sizeof(entry->psk), 0, sizeof(entry->psk));
638 : 58 : spdk_keyring_put_key(entry->key);
639 : 58 : free(entry);
640 : : }
641 : :
642 : : static int
643 : 327 : nvmf_tcp_destroy(struct spdk_nvmf_transport *transport,
644 : : spdk_nvmf_transport_destroy_done_cb cb_fn, void *cb_arg)
645 : : {
646 : : struct spdk_nvmf_tcp_transport *ttransport;
647 : : struct tcp_psk_entry *entry, *tmp;
648 : :
649 [ - + ]: 327 : assert(transport != NULL);
650 : 327 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
651 : :
652 [ - + ]: 327 : TAILQ_FOREACH_SAFE(entry, &ttransport->psks, link, tmp) {
653 [ # # ]: 0 : TAILQ_REMOVE(&ttransport->psks, entry, link);
654 : 0 : nvmf_tcp_free_psk_entry(entry);
655 : : }
656 : :
657 : 327 : spdk_poller_unregister(&ttransport->accept_poller);
658 : 327 : spdk_sock_group_unregister_interrupt(ttransport->listen_sock_group);
659 : 327 : spdk_sock_group_close(&ttransport->listen_sock_group);
660 : 327 : free(ttransport);
661 : :
662 [ + + ]: 327 : if (cb_fn) {
663 : 312 : cb_fn(cb_arg);
664 : : }
665 : 327 : return 0;
666 : : }
667 : :
668 : : static int nvmf_tcp_accept(void *ctx);
669 : :
670 : : static void nvmf_tcp_accept_cb(void *ctx, struct spdk_sock_group *group, struct spdk_sock *sock);
671 : :
672 : : static void
673 : 104 : nvmf_tcp_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bool interrupt_mode)
674 : : {
675 : 104 : }
676 : :
677 : : static struct spdk_nvmf_transport *
678 : 330 : nvmf_tcp_create(struct spdk_nvmf_transport_opts *opts)
679 : : {
680 : : struct spdk_nvmf_tcp_transport *ttransport;
681 : : uint32_t sge_count;
682 : : uint32_t min_shared_buffers;
683 : : int rc;
684 : : uint64_t period;
685 : :
686 : 330 : ttransport = calloc(1, sizeof(*ttransport));
687 [ - + ]: 330 : if (!ttransport) {
688 : 0 : return NULL;
689 : : }
690 : :
691 : 330 : TAILQ_INIT(&ttransport->ports);
692 : 330 : TAILQ_INIT(&ttransport->poll_groups);
693 : 330 : TAILQ_INIT(&ttransport->psks);
694 : :
695 : 330 : ttransport->transport.ops = &spdk_nvmf_transport_tcp;
696 : :
697 : 330 : ttransport->tcp_opts.c2h_success = SPDK_NVMF_TCP_DEFAULT_SUCCESS_OPTIMIZATION;
698 : 330 : ttransport->tcp_opts.sock_priority = SPDK_NVMF_TCP_DEFAULT_SOCK_PRIORITY;
699 : 330 : ttransport->tcp_opts.control_msg_num = SPDK_NVMF_TCP_DEFAULT_CONTROL_MSG_NUM;
700 [ + + - + ]: 642 : if (opts->transport_specific != NULL &&
701 : 312 : spdk_json_decode_object_relaxed(opts->transport_specific, tcp_transport_opts_decoder,
702 : : SPDK_COUNTOF(tcp_transport_opts_decoder),
703 : 312 : &ttransport->tcp_opts)) {
704 : 0 : SPDK_ERRLOG("spdk_json_decode_object_relaxed failed\n");
705 : 0 : free(ttransport);
706 : 0 : return NULL;
707 : : }
708 : :
709 : 330 : SPDK_NOTICELOG("*** TCP Transport Init ***\n");
710 : :
711 [ - + - + : 330 : SPDK_INFOLOG(nvmf_tcp, "*** TCP Transport Init ***\n"
- - - - ]
712 : : " Transport opts: max_ioq_depth=%d, max_io_size=%d,\n"
713 : : " max_io_qpairs_per_ctrlr=%d, io_unit_size=%d,\n"
714 : : " in_capsule_data_size=%d, max_aq_depth=%d\n"
715 : : " num_shared_buffers=%d, c2h_success=%d,\n"
716 : : " dif_insert_or_strip=%d, sock_priority=%d\n"
717 : : " abort_timeout_sec=%d, control_msg_num=%hu\n"
718 : : " ack_timeout=%d\n",
719 : : opts->max_queue_depth,
720 : : opts->max_io_size,
721 : : opts->max_qpairs_per_ctrlr - 1,
722 : : opts->io_unit_size,
723 : : opts->in_capsule_data_size,
724 : : opts->max_aq_depth,
725 : : opts->num_shared_buffers,
726 : : ttransport->tcp_opts.c2h_success,
727 : : opts->dif_insert_or_strip,
728 : : ttransport->tcp_opts.sock_priority,
729 : : opts->abort_timeout_sec,
730 : : ttransport->tcp_opts.control_msg_num,
731 : : opts->ack_timeout);
732 : :
733 [ - + ]: 330 : if (ttransport->tcp_opts.sock_priority > SPDK_NVMF_TCP_DEFAULT_MAX_SOCK_PRIORITY) {
734 : 0 : SPDK_ERRLOG("Unsupported socket_priority=%d, the current range is: 0 to %d\n"
735 : : "you can use man 7 socket to view the range of priority under SO_PRIORITY item\n",
736 : : ttransport->tcp_opts.sock_priority, SPDK_NVMF_TCP_DEFAULT_MAX_SOCK_PRIORITY);
737 : 0 : free(ttransport);
738 : 0 : return NULL;
739 : : }
740 : :
741 [ - + ]: 330 : if (ttransport->tcp_opts.control_msg_num == 0 &&
742 [ # # ]: 0 : opts->in_capsule_data_size < SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE) {
743 : 0 : SPDK_WARNLOG("TCP param control_msg_num can't be 0 if ICD is less than %u bytes. Using default value %u\n",
744 : : SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE, SPDK_NVMF_TCP_DEFAULT_CONTROL_MSG_NUM);
745 : 0 : ttransport->tcp_opts.control_msg_num = SPDK_NVMF_TCP_DEFAULT_CONTROL_MSG_NUM;
746 : : }
747 : :
748 : : /* I/O unit size cannot be larger than max I/O size */
749 [ + + ]: 330 : if (opts->io_unit_size > opts->max_io_size) {
750 : 3 : SPDK_WARNLOG("TCP param io_unit_size %u can't be larger than max_io_size %u. Using max_io_size as io_unit_size\n",
751 : : opts->io_unit_size, opts->max_io_size);
752 : 3 : opts->io_unit_size = opts->max_io_size;
753 : : }
754 : :
755 : : /* In capsule data size cannot be larger than max I/O size */
756 [ - + ]: 330 : if (opts->in_capsule_data_size > opts->max_io_size) {
757 : 0 : SPDK_WARNLOG("TCP param ICD size %u can't be larger than max_io_size %u. Using max_io_size as ICD size\n",
758 : : opts->io_unit_size, opts->max_io_size);
759 : 0 : opts->in_capsule_data_size = opts->max_io_size;
760 : : }
761 : :
762 : : /* max IO queue depth cannot be smaller than 2 or larger than 65535.
763 : : * We will not check SPDK_NVMF_TCP_MAX_IO_QUEUE_DEPTH, because max_queue_depth is 16bits and always not larger than 64k. */
764 [ - + ]: 330 : if (opts->max_queue_depth < SPDK_NVMF_TCP_MIN_IO_QUEUE_DEPTH) {
765 : 0 : SPDK_WARNLOG("TCP param max_queue_depth %u can't be smaller than %u or larger than %u. Using default value %u\n",
766 : : opts->max_queue_depth, SPDK_NVMF_TCP_MIN_IO_QUEUE_DEPTH,
767 : : SPDK_NVMF_TCP_MAX_IO_QUEUE_DEPTH, SPDK_NVMF_TCP_DEFAULT_MAX_IO_QUEUE_DEPTH);
768 : 0 : opts->max_queue_depth = SPDK_NVMF_TCP_DEFAULT_MAX_IO_QUEUE_DEPTH;
769 : : }
770 : :
771 : : /* max admin queue depth cannot be smaller than 2 or larger than 4096 */
772 [ + - ]: 330 : if (opts->max_aq_depth < SPDK_NVMF_TCP_MIN_ADMIN_QUEUE_DEPTH ||
773 [ - + ]: 330 : opts->max_aq_depth > SPDK_NVMF_TCP_MAX_ADMIN_QUEUE_DEPTH) {
774 : 0 : SPDK_WARNLOG("TCP param max_aq_depth %u can't be smaller than %u or larger than %u. Using default value %u\n",
775 : : opts->max_aq_depth, SPDK_NVMF_TCP_MIN_ADMIN_QUEUE_DEPTH,
776 : : SPDK_NVMF_TCP_MAX_ADMIN_QUEUE_DEPTH, SPDK_NVMF_TCP_DEFAULT_MAX_ADMIN_QUEUE_DEPTH);
777 : 0 : opts->max_aq_depth = SPDK_NVMF_TCP_DEFAULT_MAX_ADMIN_QUEUE_DEPTH;
778 : : }
779 : :
780 [ - + ]: 330 : sge_count = opts->max_io_size / opts->io_unit_size;
781 [ + + ]: 330 : if (sge_count > SPDK_NVMF_MAX_SGL_ENTRIES) {
782 : 3 : SPDK_ERRLOG("Unsupported IO Unit size specified, %d bytes\n", opts->io_unit_size);
783 : 3 : free(ttransport);
784 : 3 : return NULL;
785 : : }
786 : :
787 : : /* If buf_cache_size == UINT32_MAX, we will dynamically pick a cache size later that we know will fit. */
788 [ + + ]: 327 : if (opts->buf_cache_size < UINT32_MAX) {
789 : 15 : min_shared_buffers = spdk_env_get_core_count() * opts->buf_cache_size;
790 [ - + ]: 15 : if (min_shared_buffers > opts->num_shared_buffers) {
791 : 0 : SPDK_ERRLOG("There are not enough buffers to satisfy "
792 : : "per-poll group caches for each thread. (%" PRIu32 ") "
793 : : "supplied. (%" PRIu32 ") required\n", opts->num_shared_buffers, min_shared_buffers);
794 : 0 : SPDK_ERRLOG("Please specify a larger number of shared buffers\n");
795 : 0 : free(ttransport);
796 : 0 : return NULL;
797 : : }
798 : : }
799 : :
800 [ + + ]: 327 : period = spdk_interrupt_mode_is_enabled() ? 0 : opts->acceptor_poll_rate;
801 : 327 : ttransport->accept_poller = SPDK_POLLER_REGISTER(nvmf_tcp_accept, &ttransport->transport, period);
802 [ - + ]: 327 : if (!ttransport->accept_poller) {
803 : 0 : free(ttransport);
804 : 0 : return NULL;
805 : : }
806 : :
807 : 327 : spdk_poller_register_interrupt(ttransport->accept_poller, nvmf_tcp_poller_set_interrupt_mode, NULL);
808 : :
809 : 327 : ttransport->listen_sock_group = spdk_sock_group_create(NULL);
810 [ - + ]: 327 : if (ttransport->listen_sock_group == NULL) {
811 : 0 : SPDK_ERRLOG("Failed to create socket group for listen sockets\n");
812 : 0 : spdk_poller_unregister(&ttransport->accept_poller);
813 : 0 : free(ttransport);
814 : 0 : return NULL;
815 : : }
816 : :
817 [ + + ]: 327 : if (spdk_interrupt_mode_is_enabled()) {
818 : 104 : rc = SPDK_SOCK_GROUP_REGISTER_INTERRUPT(ttransport->listen_sock_group,
819 : : SPDK_INTERRUPT_EVENT_IN | SPDK_INTERRUPT_EVENT_OUT, nvmf_tcp_accept, &ttransport->transport);
820 [ - + ]: 104 : if (rc != 0) {
821 : 0 : SPDK_ERRLOG("Failed to register interrupt for listen socker sock group\n");
822 : 0 : spdk_sock_group_close(&ttransport->listen_sock_group);
823 : 0 : spdk_poller_unregister(&ttransport->accept_poller);
824 : 0 : free(ttransport);
825 : 0 : return NULL;
826 : : }
827 : : }
828 : :
829 : 327 : return &ttransport->transport;
830 : : }
831 : :
832 : : static int
833 : 1714 : nvmf_tcp_trsvcid_to_int(const char *trsvcid)
834 : : {
835 : : unsigned long long ull;
836 : 1714 : char *end = NULL;
837 : :
838 [ - + ]: 1714 : ull = strtoull(trsvcid, &end, 10);
839 [ + - + - : 1714 : if (end == NULL || end == trsvcid || *end != '\0') {
- + ]
840 : 0 : return -1;
841 : : }
842 : :
843 : : /* Valid TCP/IP port numbers are in [1, 65535] */
844 [ + - - + ]: 1714 : if (ull == 0 || ull > 65535) {
845 : 0 : return -1;
846 : : }
847 : :
848 : 1714 : return (int)ull;
849 : : }
850 : :
851 : : /**
852 : : * Canonicalize a listen address trid.
853 : : */
854 : : static int
855 : 1286 : nvmf_tcp_canon_listen_trid(struct spdk_nvme_transport_id *canon_trid,
856 : : const struct spdk_nvme_transport_id *trid)
857 : : {
858 : : int trsvcid_int;
859 : :
860 : 1286 : trsvcid_int = nvmf_tcp_trsvcid_to_int(trid->trsvcid);
861 [ - + ]: 1286 : if (trsvcid_int < 0) {
862 : 0 : return -EINVAL;
863 : : }
864 : :
865 [ - + ]: 1286 : memset(canon_trid, 0, sizeof(*canon_trid));
866 : 1286 : spdk_nvme_trid_populate_transport(canon_trid, SPDK_NVME_TRANSPORT_TCP);
867 : 1286 : canon_trid->adrfam = trid->adrfam;
868 [ - + ]: 1286 : snprintf(canon_trid->traddr, sizeof(canon_trid->traddr), "%s", trid->traddr);
869 [ - + ]: 1286 : snprintf(canon_trid->trsvcid, sizeof(canon_trid->trsvcid), "%d", trsvcid_int);
870 : :
871 : 1286 : return 0;
872 : : }
873 : :
874 : : /**
875 : : * Find an existing listening port.
876 : : */
877 : : static struct spdk_nvmf_tcp_port *
878 : 1286 : nvmf_tcp_find_port(struct spdk_nvmf_tcp_transport *ttransport,
879 : : const struct spdk_nvme_transport_id *trid)
880 : : {
881 : 136 : struct spdk_nvme_transport_id canon_trid;
882 : : struct spdk_nvmf_tcp_port *port;
883 : :
884 [ - + ]: 1286 : if (nvmf_tcp_canon_listen_trid(&canon_trid, trid) != 0) {
885 : 0 : return NULL;
886 : : }
887 : :
888 [ + - ]: 2036 : TAILQ_FOREACH(port, &ttransport->ports, link) {
889 [ + + ]: 2036 : if (spdk_nvme_transport_id_compare(&canon_trid, port->trid) == 0) {
890 : 1286 : return port;
891 : : }
892 : : }
893 : :
894 : 0 : return NULL;
895 : : }
896 : :
897 : : static int
898 : 190 : tcp_sock_get_key(uint8_t *out, int out_len, const char **cipher, const char *pskid,
899 : : void *get_key_ctx)
900 : : {
901 : : struct tcp_psk_entry *entry;
902 : 190 : struct spdk_nvmf_tcp_transport *ttransport = get_key_ctx;
903 : : size_t psk_len;
904 : : int rc;
905 : :
906 [ + + ]: 200 : TAILQ_FOREACH(entry, &ttransport->psks, link) {
907 [ - + - + : 190 : if (strcmp(pskid, entry->pskid) != 0) {
+ + ]
908 : 10 : continue;
909 : : }
910 : :
911 : 180 : psk_len = entry->psk_size;
912 [ - + ]: 180 : if ((size_t)out_len < psk_len) {
913 : 0 : SPDK_ERRLOG("Out buffer of size: %" PRIu32 " cannot fit PSK of len: %lu\n",
914 : : out_len, psk_len);
915 : 0 : return -ENOBUFS;
916 : : }
917 : :
918 : : /* Convert PSK to the TLS PSK format. */
919 : 180 : rc = nvme_tcp_derive_tls_psk(entry->psk, psk_len, pskid, out, out_len,
920 : : entry->tls_cipher_suite);
921 [ - + ]: 180 : if (rc < 0) {
922 : 0 : SPDK_ERRLOG("Could not generate TLS PSK\n");
923 : : }
924 : :
925 [ + + - ]: 180 : switch (entry->tls_cipher_suite) {
926 : 95 : case NVME_TCP_CIPHER_AES_128_GCM_SHA256:
927 : 95 : *cipher = "TLS_AES_128_GCM_SHA256";
928 : 95 : break;
929 : 85 : case NVME_TCP_CIPHER_AES_256_GCM_SHA384:
930 : 85 : *cipher = "TLS_AES_256_GCM_SHA384";
931 : 85 : break;
932 : 0 : default:
933 : 0 : *cipher = NULL;
934 : 0 : return -ENOTSUP;
935 : : }
936 : :
937 : 180 : return rc;
938 : : }
939 : :
940 : 10 : SPDK_ERRLOG("Could not find PSK for identity: %s\n", pskid);
941 : :
942 : 10 : return -EINVAL;
943 : : }
944 : :
945 : : static int
946 : 428 : nvmf_tcp_listen(struct spdk_nvmf_transport *transport, const struct spdk_nvme_transport_id *trid,
947 : : struct spdk_nvmf_listen_opts *listen_opts)
948 : : {
949 : : struct spdk_nvmf_tcp_transport *ttransport;
950 : : struct spdk_nvmf_tcp_port *port;
951 : : int trsvcid_int;
952 : : uint8_t adrfam;
953 : : const char *sock_impl_name;
954 : 19 : struct spdk_sock_impl_opts impl_opts;
955 : 428 : size_t impl_opts_size = sizeof(impl_opts);
956 : 19 : struct spdk_sock_opts opts;
957 : : int rc;
958 : :
959 [ - + ]: 428 : if (!strlen(trid->trsvcid)) {
960 : 0 : SPDK_ERRLOG("Service id is required\n");
961 : 0 : return -EINVAL;
962 : : }
963 : :
964 : 428 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
965 : :
966 : 428 : trsvcid_int = nvmf_tcp_trsvcid_to_int(trid->trsvcid);
967 [ - + ]: 428 : if (trsvcid_int < 0) {
968 : 0 : SPDK_ERRLOG("Invalid trsvcid '%s'\n", trid->trsvcid);
969 : 0 : return -EINVAL;
970 : : }
971 : :
972 : 428 : port = calloc(1, sizeof(*port));
973 [ - + ]: 428 : if (!port) {
974 : 0 : SPDK_ERRLOG("Port allocation failed\n");
975 : 0 : return -ENOMEM;
976 : : }
977 : :
978 : 428 : port->trid = trid;
979 : :
980 : 428 : sock_impl_name = NULL;
981 : :
982 : 428 : opts.opts_size = sizeof(opts);
983 : 428 : spdk_sock_get_default_opts(&opts);
984 : 428 : opts.priority = ttransport->tcp_opts.sock_priority;
985 : 428 : opts.ack_timeout = transport->opts.ack_timeout;
986 [ - + + + ]: 428 : if (listen_opts->secure_channel) {
987 [ - + + - ]: 55 : if (!g_tls_log) {
988 : 55 : SPDK_NOTICELOG("TLS support is considered experimental\n");
989 : 55 : g_tls_log = true;
990 : : }
991 : 55 : sock_impl_name = "ssl";
992 : 55 : spdk_sock_impl_get_opts(sock_impl_name, &impl_opts, &impl_opts_size);
993 : 55 : impl_opts.tls_version = SPDK_TLS_VERSION_1_3;
994 : 55 : impl_opts.get_key = tcp_sock_get_key;
995 : 55 : impl_opts.get_key_ctx = ttransport;
996 : 55 : impl_opts.tls_cipher_suites = "TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256";
997 : 55 : opts.impl_opts = &impl_opts;
998 : 55 : opts.impl_opts_size = sizeof(impl_opts);
999 : : }
1000 : :
1001 : 428 : port->listen_sock = spdk_sock_listen_ext(trid->traddr, trsvcid_int,
1002 : : sock_impl_name, &opts);
1003 [ - + ]: 428 : if (port->listen_sock == NULL) {
1004 : 0 : SPDK_ERRLOG("spdk_sock_listen(%s, %d) failed: %s (%d)\n",
1005 : : trid->traddr, trsvcid_int,
1006 : : spdk_strerror(errno), errno);
1007 : 0 : free(port);
1008 : 0 : return -errno;
1009 : : }
1010 : :
1011 [ + - ]: 428 : if (spdk_sock_is_ipv4(port->listen_sock)) {
1012 : 428 : adrfam = SPDK_NVMF_ADRFAM_IPV4;
1013 [ # # ]: 0 : } else if (spdk_sock_is_ipv6(port->listen_sock)) {
1014 : 0 : adrfam = SPDK_NVMF_ADRFAM_IPV6;
1015 : : } else {
1016 : 0 : SPDK_ERRLOG("Unhandled socket type\n");
1017 : 0 : adrfam = 0;
1018 : : }
1019 : :
1020 [ - + ]: 428 : if (adrfam != trid->adrfam) {
1021 : 0 : SPDK_ERRLOG("Socket address family mismatch\n");
1022 : 0 : spdk_sock_close(&port->listen_sock);
1023 : 0 : free(port);
1024 : 0 : return -EINVAL;
1025 : : }
1026 : :
1027 : 428 : rc = spdk_sock_group_add_sock(ttransport->listen_sock_group, port->listen_sock, nvmf_tcp_accept_cb,
1028 : : port);
1029 [ - + ]: 428 : if (rc < 0) {
1030 : 0 : SPDK_ERRLOG("Failed to add socket to the listen socket group\n");
1031 : 0 : spdk_sock_close(&port->listen_sock);
1032 : 0 : free(port);
1033 : 0 : return -errno;
1034 : : }
1035 : :
1036 : 428 : port->transport = transport;
1037 : :
1038 : 428 : SPDK_NOTICELOG("*** NVMe/TCP Target Listening on %s port %s ***\n",
1039 : : trid->traddr, trid->trsvcid);
1040 : :
1041 : 428 : TAILQ_INSERT_TAIL(&ttransport->ports, port, link);
1042 : 428 : return 0;
1043 : : }
1044 : :
1045 : : static void
1046 : 428 : nvmf_tcp_stop_listen(struct spdk_nvmf_transport *transport,
1047 : : const struct spdk_nvme_transport_id *trid)
1048 : : {
1049 : : struct spdk_nvmf_tcp_transport *ttransport;
1050 : : struct spdk_nvmf_tcp_port *port;
1051 : :
1052 : 428 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
1053 : :
1054 [ - + - + ]: 428 : SPDK_DEBUGLOG(nvmf_tcp, "Removing listen address %s port %s\n",
1055 : : trid->traddr, trid->trsvcid);
1056 : :
1057 : 428 : port = nvmf_tcp_find_port(ttransport, trid);
1058 [ + - ]: 428 : if (port) {
1059 : 428 : spdk_sock_group_remove_sock(ttransport->listen_sock_group, port->listen_sock);
1060 [ + + ]: 428 : TAILQ_REMOVE(&ttransport->ports, port, link);
1061 : 428 : spdk_sock_close(&port->listen_sock);
1062 : 428 : free(port);
1063 : : }
1064 : 428 : }
1065 : :
1066 : : static void nvmf_tcp_qpair_set_recv_state(struct spdk_nvmf_tcp_qpair *tqpair,
1067 : : enum nvme_tcp_pdu_recv_state state);
1068 : :
1069 : : static void
1070 : 73686 : nvmf_tcp_qpair_set_state(struct spdk_nvmf_tcp_qpair *tqpair, enum nvme_tcp_qpair_state state)
1071 : : {
1072 : 73686 : tqpair->state = state;
1073 [ + + + + ]: 73686 : spdk_trace_record(TRACE_TCP_QP_STATE_CHANGE, tqpair->qpair.trace_id, 0, 0,
1074 : : (uint64_t)tqpair->state);
1075 : 73686 : }
1076 : :
1077 : : static void
1078 : 302094 : nvmf_tcp_qpair_disconnect(struct spdk_nvmf_tcp_qpair *tqpair)
1079 : : {
1080 [ - + - + ]: 302094 : SPDK_DEBUGLOG(nvmf_tcp, "Disconnecting qpair %p\n", tqpair);
1081 : :
1082 [ + + + + ]: 302094 : spdk_trace_record(TRACE_TCP_QP_DISCONNECT, tqpair->qpair.trace_id, 0, 0);
1083 : :
1084 [ + + ]: 302094 : if (tqpair->state <= NVME_TCP_QPAIR_STATE_RUNNING) {
1085 : 12141 : nvmf_tcp_qpair_set_state(tqpair, NVME_TCP_QPAIR_STATE_EXITING);
1086 [ - + ]: 12141 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_ERROR);
1087 : 12141 : spdk_poller_unregister(&tqpair->timeout_poller);
1088 : :
1089 : : /* This will end up calling nvmf_tcp_close_qpair */
1090 : 12141 : spdk_nvmf_qpair_disconnect(&tqpair->qpair);
1091 : : }
1092 : 302094 : }
1093 : :
1094 : : static void
1095 : 24644 : _mgmt_pdu_write_done(void *_tqpair, int err)
1096 : : {
1097 : 24644 : struct spdk_nvmf_tcp_qpair *tqpair = _tqpair;
1098 : 24644 : struct nvme_tcp_pdu *pdu = tqpair->mgmt_pdu;
1099 : :
1100 [ + + ]: 24644 : if (spdk_unlikely(err != 0)) {
1101 : 48 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
1102 : 48 : return;
1103 : : }
1104 : :
1105 [ - + ]: 24596 : assert(pdu->cb_fn != NULL);
1106 : 24596 : pdu->cb_fn(pdu->cb_arg);
1107 : : }
1108 : :
1109 : : static void
1110 : 31948240 : _req_pdu_write_done(void *req, int err)
1111 : : {
1112 : 31948240 : struct spdk_nvmf_tcp_req *tcp_req = req;
1113 : 31948240 : struct nvme_tcp_pdu *pdu = tcp_req->pdu;
1114 : 31948240 : struct spdk_nvmf_tcp_qpair *tqpair = pdu->qpair;
1115 : :
1116 [ - + - + ]: 31948240 : assert(tcp_req->pdu_in_use);
1117 : 31948240 : tcp_req->pdu_in_use = false;
1118 : :
1119 : : /* If the request is in a completed state, we're waiting for write completion to free it */
1120 [ - + ]: 31948240 : if (spdk_unlikely(tcp_req->state == TCP_REQUEST_STATE_COMPLETED)) {
1121 : 0 : nvmf_tcp_request_free(tcp_req);
1122 : 0 : return;
1123 : : }
1124 : :
1125 [ + + ]: 31948240 : if (spdk_unlikely(err != 0)) {
1126 : 2334 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
1127 : 2334 : return;
1128 : : }
1129 : :
1130 [ - + ]: 31945906 : assert(pdu->cb_fn != NULL);
1131 : 31945906 : pdu->cb_fn(pdu->cb_arg);
1132 : : }
1133 : :
1134 : : static void
1135 : 12346 : _pdu_write_done(struct nvme_tcp_pdu *pdu, int err)
1136 : : {
1137 : 12346 : pdu->sock_req.cb_fn(pdu->sock_req.cb_arg, err);
1138 : 12346 : }
1139 : :
1140 : : static void
1141 : 31960607 : _tcp_write_pdu(struct nvme_tcp_pdu *pdu)
1142 : : {
1143 : : int rc;
1144 : 121811 : uint32_t mapped_length;
1145 : 31960607 : struct spdk_nvmf_tcp_qpair *tqpair = pdu->qpair;
1146 : :
1147 : 31960630 : pdu->sock_req.iovcnt = nvme_tcp_build_iovs(pdu->iov, SPDK_COUNTOF(pdu->iov), pdu,
1148 [ - + - + ]: 31960607 : tqpair->host_hdgst_enable, tqpair->host_ddgst_enable, &mapped_length);
1149 : 31960607 : spdk_sock_writev_async(tqpair->sock, &pdu->sock_req);
1150 : :
1151 [ + + ]: 31960607 : if (pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP ||
1152 [ + + ]: 31948306 : pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ) {
1153 : : /* Try to force the send immediately. */
1154 : 12346 : rc = spdk_sock_flush(tqpair->sock);
1155 [ + + + - ]: 12346 : if (rc > 0 && (uint32_t)rc == mapped_length) {
1156 : 12298 : _pdu_write_done(pdu, 0);
1157 : : } else {
1158 [ + + ]: 48 : SPDK_ERRLOG("Could not write %s to socket: rc=%d, errno=%d\n",
1159 : : pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP ?
1160 : : "IC_RESP" : "TERM_REQ", rc, errno);
1161 [ - + ]: 48 : _pdu_write_done(pdu, rc >= 0 ? -EAGAIN : -errno);
1162 : : }
1163 : : }
1164 : 31960607 : }
1165 : :
1166 : : static void
1167 : 1130945 : data_crc32_accel_done(void *cb_arg, int status)
1168 : : {
1169 : 1130945 : struct nvme_tcp_pdu *pdu = cb_arg;
1170 : :
1171 [ - + ]: 1130945 : if (spdk_unlikely(status)) {
1172 : 0 : SPDK_ERRLOG("Failed to compute the data digest for pdu =%p\n", pdu);
1173 : 0 : _pdu_write_done(pdu, status);
1174 : 0 : return;
1175 : : }
1176 : :
1177 : 1130945 : pdu->data_digest_crc32 ^= SPDK_CRC32C_XOR;
1178 : 1130945 : MAKE_DIGEST_WORD(pdu->data_digest, pdu->data_digest_crc32);
1179 : :
1180 : 1130945 : _tcp_write_pdu(pdu);
1181 : : }
1182 : :
1183 : : static void
1184 : 31960607 : pdu_data_crc32_compute(struct nvme_tcp_pdu *pdu)
1185 : : {
1186 : 31960607 : struct spdk_nvmf_tcp_qpair *tqpair = pdu->qpair;
1187 : 31960607 : int rc = 0;
1188 : :
1189 : : /* Data Digest */
1190 [ + + + + : 31960607 : if (pdu->data_len > 0 && g_nvme_tcp_ddgst[pdu->hdr.common.pdu_type] && tqpair->host_ddgst_enable) {
+ + - + +
+ ]
1191 : : /* Only support this limitated case for the first step */
1192 [ + + + - : 1130945 : if (spdk_likely(!pdu->dif_ctx && (pdu->data_len % SPDK_NVME_TCP_DIGEST_ALIGNMENT == 0)
+ + + - ]
1193 : : && tqpair->group)) {
1194 : 967553 : rc = spdk_accel_submit_crc32cv(tqpair->group->accel_channel, &pdu->data_digest_crc32, pdu->data_iov,
1195 : : pdu->data_iovcnt, 0, data_crc32_accel_done, pdu);
1196 [ + - ]: 967553 : if (spdk_likely(rc == 0)) {
1197 : 967553 : return;
1198 : : }
1199 : : } else {
1200 : 163392 : pdu->data_digest_crc32 = nvme_tcp_pdu_calc_data_digest(pdu);
1201 : : }
1202 : 163392 : data_crc32_accel_done(pdu, rc);
1203 : : } else {
1204 : 30829662 : _tcp_write_pdu(pdu);
1205 : : }
1206 : : }
1207 : :
1208 : : static void
1209 : 31960607 : nvmf_tcp_qpair_write_pdu(struct spdk_nvmf_tcp_qpair *tqpair,
1210 : : struct nvme_tcp_pdu *pdu,
1211 : : nvme_tcp_qpair_xfer_complete_cb cb_fn,
1212 : : void *cb_arg)
1213 : : {
1214 : : int hlen;
1215 : : uint32_t crc32c;
1216 : :
1217 [ - + ]: 31960607 : assert(tqpair->pdu_in_progress != pdu);
1218 : :
1219 : 31960607 : hlen = pdu->hdr.common.hlen;
1220 : 31960607 : pdu->cb_fn = cb_fn;
1221 : 31960607 : pdu->cb_arg = cb_arg;
1222 : :
1223 : 31960607 : pdu->iov[0].iov_base = &pdu->hdr.raw;
1224 : 31960607 : pdu->iov[0].iov_len = hlen;
1225 : :
1226 : : /* Header Digest */
1227 [ + + + + : 31960607 : if (g_nvme_tcp_hdgst[pdu->hdr.common.pdu_type] && tqpair->host_hdgst_enable) {
- + + + ]
1228 : 1239175 : crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
1229 : 1239175 : MAKE_DIGEST_WORD((uint8_t *)pdu->hdr.raw + hlen, crc32c);
1230 : : }
1231 : :
1232 : : /* Data Digest */
1233 : 31960607 : pdu_data_crc32_compute(pdu);
1234 : 31960607 : }
1235 : :
1236 : : static void
1237 : 12346 : nvmf_tcp_qpair_write_mgmt_pdu(struct spdk_nvmf_tcp_qpair *tqpair,
1238 : : nvme_tcp_qpair_xfer_complete_cb cb_fn,
1239 : : void *cb_arg)
1240 : : {
1241 : 12346 : struct nvme_tcp_pdu *pdu = tqpair->mgmt_pdu;
1242 : :
1243 : 12346 : pdu->sock_req.cb_fn = _mgmt_pdu_write_done;
1244 : 12346 : pdu->sock_req.cb_arg = tqpair;
1245 : :
1246 : 12346 : nvmf_tcp_qpair_write_pdu(tqpair, pdu, cb_fn, cb_arg);
1247 : 12346 : }
1248 : :
1249 : : static void
1250 : 31948261 : nvmf_tcp_qpair_write_req_pdu(struct spdk_nvmf_tcp_qpair *tqpair,
1251 : : struct spdk_nvmf_tcp_req *tcp_req,
1252 : : nvme_tcp_qpair_xfer_complete_cb cb_fn,
1253 : : void *cb_arg)
1254 : : {
1255 : 31948261 : struct nvme_tcp_pdu *pdu = tcp_req->pdu;
1256 : :
1257 : 31948261 : pdu->sock_req.cb_fn = _req_pdu_write_done;
1258 : 31948261 : pdu->sock_req.cb_arg = tcp_req;
1259 : :
1260 [ - + - + ]: 31948261 : assert(!tcp_req->pdu_in_use);
1261 : 31948261 : tcp_req->pdu_in_use = true;
1262 : :
1263 : 31948261 : nvmf_tcp_qpair_write_pdu(tqpair, pdu, cb_fn, cb_arg);
1264 : 31948261 : }
1265 : :
1266 : : static int
1267 : 12327 : nvmf_tcp_qpair_init_mem_resource(struct spdk_nvmf_tcp_qpair *tqpair)
1268 : : {
1269 : : uint32_t i;
1270 : : struct spdk_nvmf_transport_opts *opts;
1271 : : uint32_t in_capsule_data_size;
1272 : :
1273 : 12327 : opts = &tqpair->qpair.transport->opts;
1274 : :
1275 : 12327 : in_capsule_data_size = opts->in_capsule_data_size;
1276 [ - + + + ]: 12327 : if (opts->dif_insert_or_strip) {
1277 : 171 : in_capsule_data_size = SPDK_BDEV_BUF_SIZE_WITH_MD(in_capsule_data_size);
1278 : : }
1279 : :
1280 : 12327 : tqpair->resource_count = opts->max_queue_depth;
1281 : :
1282 : 12327 : tqpair->reqs = calloc(tqpair->resource_count, sizeof(*tqpair->reqs));
1283 [ - + ]: 12327 : if (!tqpair->reqs) {
1284 : 0 : SPDK_ERRLOG("Unable to allocate reqs on tqpair=%p\n", tqpair);
1285 : 0 : return -1;
1286 : : }
1287 : :
1288 [ + + ]: 12327 : if (in_capsule_data_size) {
1289 : 11562 : tqpair->bufs = spdk_zmalloc(tqpair->resource_count * in_capsule_data_size, 0x1000,
1290 : : NULL, SPDK_ENV_LCORE_ID_ANY,
1291 : : SPDK_MALLOC_DMA);
1292 [ - + ]: 11562 : if (!tqpair->bufs) {
1293 : 0 : SPDK_ERRLOG("Unable to allocate bufs on tqpair=%p.\n", tqpair);
1294 : 0 : return -1;
1295 : : }
1296 : : }
1297 : : /* prepare memory space for receiving pdus and tcp_req */
1298 : : /* Add additional 1 member, which will be used for mgmt_pdu owned by the tqpair */
1299 : 12327 : tqpair->pdus = spdk_dma_zmalloc((2 * tqpair->resource_count + 1) * sizeof(*tqpair->pdus), 0x1000,
1300 : : NULL);
1301 [ - + ]: 12327 : if (!tqpair->pdus) {
1302 : 0 : SPDK_ERRLOG("Unable to allocate pdu pool on tqpair =%p.\n", tqpair);
1303 : 0 : return -1;
1304 : : }
1305 : :
1306 [ + + ]: 1590183 : for (i = 0; i < tqpair->resource_count; i++) {
1307 : 1577856 : struct spdk_nvmf_tcp_req *tcp_req = &tqpair->reqs[i];
1308 : :
1309 : 1577856 : tcp_req->ttag = i + 1;
1310 : 1577856 : tcp_req->req.qpair = &tqpair->qpair;
1311 : :
1312 : 1577856 : tcp_req->pdu = &tqpair->pdus[i];
1313 : 1577856 : tcp_req->pdu->qpair = tqpair;
1314 : :
1315 : : /* Set up memory to receive commands */
1316 [ + + ]: 1577856 : if (tqpair->bufs) {
1317 : 1479936 : tcp_req->buf = (void *)((uintptr_t)tqpair->bufs + (i * in_capsule_data_size));
1318 : : }
1319 : :
1320 : : /* Set the cmdn and rsp */
1321 : 1577856 : tcp_req->req.rsp = (union nvmf_c2h_msg *)&tcp_req->rsp;
1322 : 1577856 : tcp_req->req.cmd = (union nvmf_h2c_msg *)&tcp_req->cmd;
1323 : :
1324 : 1577856 : tcp_req->req.stripped_data = NULL;
1325 : :
1326 : : /* Initialize request state to FREE */
1327 : 1577856 : tcp_req->state = TCP_REQUEST_STATE_FREE;
1328 : 1577856 : TAILQ_INSERT_TAIL(&tqpair->tcp_req_free_queue, tcp_req, state_link);
1329 : 1577856 : tqpair->state_cntr[TCP_REQUEST_STATE_FREE]++;
1330 : : }
1331 : :
1332 [ + + ]: 1590183 : for (; i < 2 * tqpair->resource_count; i++) {
1333 : 1577856 : struct nvme_tcp_pdu *pdu = &tqpair->pdus[i];
1334 : :
1335 : 1577856 : pdu->qpair = tqpair;
1336 : 1577856 : SLIST_INSERT_HEAD(&tqpair->tcp_pdu_free_queue, pdu, slist);
1337 : : }
1338 : :
1339 : 12327 : tqpair->mgmt_pdu = &tqpair->pdus[i];
1340 : 12327 : tqpair->mgmt_pdu->qpair = tqpair;
1341 : 12327 : tqpair->pdu_in_progress = SLIST_FIRST(&tqpair->tcp_pdu_free_queue);
1342 : 12327 : SLIST_REMOVE_HEAD(&tqpair->tcp_pdu_free_queue, slist);
1343 : 12327 : tqpair->tcp_pdu_working_count = 1;
1344 : :
1345 : 12327 : tqpair->recv_buf_size = (in_capsule_data_size + sizeof(struct spdk_nvme_tcp_cmd) + 2 *
1346 : : SPDK_NVME_TCP_DIGEST_LEN) * SPDK_NVMF_TCP_RECV_BUF_SIZE_FACTOR;
1347 : :
1348 : 12327 : return 0;
1349 : : }
1350 : :
1351 : : static int
1352 : 12327 : nvmf_tcp_qpair_init(struct spdk_nvmf_qpair *qpair)
1353 : : {
1354 : : struct spdk_nvmf_tcp_qpair *tqpair;
1355 : :
1356 : 12327 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
1357 : :
1358 [ - + - + ]: 12327 : SPDK_DEBUGLOG(nvmf_tcp, "New TCP Connection: %p\n", qpair);
1359 : :
1360 [ + + + + ]: 12327 : spdk_trace_record(TRACE_TCP_QP_CREATE, tqpair->qpair.trace_id, 0, 0);
1361 : :
1362 : : /* Initialise request state queues of the qpair */
1363 : 12327 : TAILQ_INIT(&tqpair->tcp_req_free_queue);
1364 : 12327 : TAILQ_INIT(&tqpair->tcp_req_working_queue);
1365 : 12327 : SLIST_INIT(&tqpair->tcp_pdu_free_queue);
1366 : 12327 : tqpair->qpair.queue_depth = 0;
1367 : :
1368 : 12327 : tqpair->host_hdgst_enable = true;
1369 : 12327 : tqpair->host_ddgst_enable = true;
1370 : :
1371 : 12327 : return 0;
1372 : : }
1373 : :
1374 : : static int
1375 : 12324 : nvmf_tcp_qpair_sock_init(struct spdk_nvmf_tcp_qpair *tqpair)
1376 : : {
1377 : 86 : char saddr[32], caddr[32];
1378 : 86 : uint16_t sport, cport;
1379 : 86 : char owner[256];
1380 : : int rc;
1381 : :
1382 : 12324 : rc = spdk_sock_getaddr(tqpair->sock, saddr, sizeof(saddr), &sport,
1383 : : caddr, sizeof(caddr), &cport);
1384 [ - + ]: 12324 : if (rc != 0) {
1385 : 0 : SPDK_ERRLOG("spdk_sock_getaddr() failed\n");
1386 : 0 : return rc;
1387 : : }
1388 : 12324 : snprintf(owner, sizeof(owner), "%s:%d", caddr, cport);
1389 : 12324 : tqpair->qpair.trace_id = spdk_trace_register_owner(OWNER_TYPE_NVMF_TCP, owner);
1390 [ + + + + ]: 12324 : spdk_trace_record(TRACE_TCP_QP_SOCK_INIT, tqpair->qpair.trace_id, 0, 0);
1391 : :
1392 : : /* set low water mark */
1393 : 12324 : rc = spdk_sock_set_recvlowat(tqpair->sock, 1);
1394 [ - + ]: 12324 : if (rc != 0) {
1395 : 0 : SPDK_ERRLOG("spdk_sock_set_recvlowat() failed\n");
1396 : 0 : return rc;
1397 : : }
1398 : :
1399 : 12324 : return 0;
1400 : : }
1401 : :
1402 : : static void
1403 : 12324 : nvmf_tcp_handle_connect(struct spdk_nvmf_tcp_port *port, struct spdk_sock *sock)
1404 : : {
1405 : : struct spdk_nvmf_tcp_qpair *tqpair;
1406 : : int rc;
1407 : :
1408 [ - + - + ]: 12324 : SPDK_DEBUGLOG(nvmf_tcp, "New connection accepted on %s port %s\n",
1409 : : port->trid->traddr, port->trid->trsvcid);
1410 : :
1411 : 12324 : tqpair = calloc(1, sizeof(struct spdk_nvmf_tcp_qpair));
1412 [ - + ]: 12324 : if (tqpair == NULL) {
1413 : 0 : SPDK_ERRLOG("Could not allocate new connection.\n");
1414 : 0 : spdk_sock_close(&sock);
1415 : 0 : return;
1416 : : }
1417 : :
1418 : 12324 : tqpair->sock = sock;
1419 : 12324 : tqpair->state_cntr[TCP_REQUEST_STATE_FREE] = 0;
1420 : 12324 : tqpair->port = port;
1421 : 12324 : tqpair->qpair.transport = port->transport;
1422 : :
1423 : 24648 : rc = spdk_sock_getaddr(tqpair->sock, tqpair->target_addr,
1424 : : sizeof(tqpair->target_addr), &tqpair->target_port,
1425 : 12324 : tqpair->initiator_addr, sizeof(tqpair->initiator_addr),
1426 : : &tqpair->initiator_port);
1427 [ - + ]: 12324 : if (rc < 0) {
1428 : 0 : SPDK_ERRLOG("spdk_sock_getaddr() failed of tqpair=%p\n", tqpair);
1429 : 0 : nvmf_tcp_qpair_destroy(tqpair);
1430 : 0 : return;
1431 : : }
1432 : :
1433 : 12324 : spdk_nvmf_tgt_new_qpair(port->transport->tgt, &tqpair->qpair);
1434 : : }
1435 : :
1436 : : static uint32_t
1437 : 78717 : nvmf_tcp_port_accept(struct spdk_nvmf_tcp_port *port)
1438 : : {
1439 : : struct spdk_sock *sock;
1440 : 78717 : uint32_t count = 0;
1441 : : int i;
1442 : :
1443 [ + - ]: 91041 : for (i = 0; i < NVMF_TCP_MAX_ACCEPT_SOCK_ONE_TIME; i++) {
1444 : 91041 : sock = spdk_sock_accept(port->listen_sock);
1445 [ + + ]: 91041 : if (sock == NULL) {
1446 : 78717 : break;
1447 : : }
1448 : 12324 : count++;
1449 : 12324 : nvmf_tcp_handle_connect(port, sock);
1450 : : }
1451 : :
1452 : 78717 : return count;
1453 : : }
1454 : :
1455 : : static int
1456 : 268349 : nvmf_tcp_accept(void *ctx)
1457 : : {
1458 : 268349 : struct spdk_nvmf_transport *transport = ctx;
1459 : : struct spdk_nvmf_tcp_transport *ttransport;
1460 : : int count;
1461 : :
1462 : 268349 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
1463 : :
1464 : 268349 : count = spdk_sock_group_poll(ttransport->listen_sock_group);
1465 [ - + ]: 268349 : if (count < 0) {
1466 : 0 : SPDK_ERRLOG("Fail in TCP listen socket group poll\n");
1467 : : }
1468 : :
1469 : 268349 : return count != 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE;
1470 : : }
1471 : :
1472 : : static void
1473 : 78717 : nvmf_tcp_accept_cb(void *ctx, struct spdk_sock_group *group, struct spdk_sock *sock)
1474 : : {
1475 : 78717 : struct spdk_nvmf_tcp_port *port = ctx;
1476 : :
1477 : 78717 : nvmf_tcp_port_accept(port);
1478 : 78717 : }
1479 : :
1480 : : static void
1481 : 858 : nvmf_tcp_discover(struct spdk_nvmf_transport *transport,
1482 : : struct spdk_nvme_transport_id *trid,
1483 : : struct spdk_nvmf_discovery_log_page_entry *entry)
1484 : : {
1485 : : struct spdk_nvmf_tcp_port *port;
1486 : : struct spdk_nvmf_tcp_transport *ttransport;
1487 : :
1488 : 858 : entry->trtype = SPDK_NVMF_TRTYPE_TCP;
1489 : 858 : entry->adrfam = trid->adrfam;
1490 : :
1491 : 858 : spdk_strcpy_pad(entry->trsvcid, trid->trsvcid, sizeof(entry->trsvcid), ' ');
1492 : 858 : spdk_strcpy_pad(entry->traddr, trid->traddr, sizeof(entry->traddr), ' ');
1493 : :
1494 : 858 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
1495 : 858 : port = nvmf_tcp_find_port(ttransport, trid);
1496 : :
1497 [ - + ]: 858 : assert(port != NULL);
1498 : :
1499 [ - + - + ]: 858 : if (strcmp(spdk_sock_get_impl_name(port->listen_sock), "ssl") == 0) {
1500 : 0 : entry->treq.secure_channel = SPDK_NVMF_TREQ_SECURE_CHANNEL_REQUIRED;
1501 : 0 : entry->tsas.tcp.sectype = SPDK_NVME_TCP_SECURITY_TLS_1_3;
1502 : : } else {
1503 : 858 : entry->treq.secure_channel = SPDK_NVMF_TREQ_SECURE_CHANNEL_NOT_REQUIRED;
1504 : 858 : entry->tsas.tcp.sectype = SPDK_NVME_TCP_SECURITY_NONE;
1505 : : }
1506 : 858 : }
1507 : :
1508 : : static struct spdk_nvmf_tcp_control_msg_list *
1509 : 693 : nvmf_tcp_control_msg_list_create(uint16_t num_messages)
1510 : : {
1511 : : struct spdk_nvmf_tcp_control_msg_list *list;
1512 : : struct spdk_nvmf_tcp_control_msg *msg;
1513 : : uint16_t i;
1514 : :
1515 : 693 : list = calloc(1, sizeof(*list));
1516 [ - + ]: 693 : if (!list) {
1517 : 0 : SPDK_ERRLOG("Failed to allocate memory for list structure\n");
1518 : 0 : return NULL;
1519 : : }
1520 : :
1521 : 693 : list->msg_buf = spdk_zmalloc(num_messages * SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE,
1522 : : NVMF_DATA_BUFFER_ALIGNMENT, NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
1523 [ - + ]: 693 : if (!list->msg_buf) {
1524 : 0 : SPDK_ERRLOG("Failed to allocate memory for control message buffers\n");
1525 : 0 : free(list);
1526 : 0 : return NULL;
1527 : : }
1528 : :
1529 : 693 : STAILQ_INIT(&list->free_msgs);
1530 : :
1531 [ + + ]: 22869 : for (i = 0; i < num_messages; i++) {
1532 : 22176 : msg = (struct spdk_nvmf_tcp_control_msg *)((char *)list->msg_buf + i *
1533 : : SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE);
1534 : 22176 : STAILQ_INSERT_TAIL(&list->free_msgs, msg, link);
1535 : : }
1536 : :
1537 : 693 : return list;
1538 : : }
1539 : :
1540 : : static void
1541 : 693 : nvmf_tcp_control_msg_list_free(struct spdk_nvmf_tcp_control_msg_list *list)
1542 : : {
1543 [ - + ]: 693 : if (!list) {
1544 : 0 : return;
1545 : : }
1546 : :
1547 : 693 : spdk_free(list->msg_buf);
1548 : 693 : free(list);
1549 : : }
1550 : :
1551 : : static int nvmf_tcp_poll_group_poll(struct spdk_nvmf_transport_poll_group *group);
1552 : :
1553 : : static int
1554 : 219699206 : nvmf_tcp_poll_group_intr(void *ctx)
1555 : : {
1556 : 219699206 : struct spdk_nvmf_transport_poll_group *group = ctx;
1557 : 219699206 : int ret = 0;
1558 : :
1559 : 219699206 : ret = nvmf_tcp_poll_group_poll(group);
1560 : :
1561 : 219699206 : return ret != 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE;
1562 : : }
1563 : :
1564 : : static struct spdk_nvmf_transport_poll_group *
1565 : 693 : nvmf_tcp_poll_group_create(struct spdk_nvmf_transport *transport,
1566 : : struct spdk_nvmf_poll_group *group)
1567 : : {
1568 : : struct spdk_nvmf_tcp_transport *ttransport;
1569 : : struct spdk_nvmf_tcp_poll_group *tgroup;
1570 : : int rc;
1571 : :
1572 : 693 : tgroup = calloc(1, sizeof(*tgroup));
1573 [ - + ]: 693 : if (!tgroup) {
1574 : 0 : return NULL;
1575 : : }
1576 : :
1577 : 693 : tgroup->sock_group = spdk_sock_group_create(&tgroup->group);
1578 [ - + ]: 693 : if (!tgroup->sock_group) {
1579 : 0 : goto cleanup;
1580 : : }
1581 : :
1582 : 693 : TAILQ_INIT(&tgroup->qpairs);
1583 : 693 : TAILQ_INIT(&tgroup->await_req);
1584 : :
1585 : 693 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
1586 : :
1587 [ + - ]: 693 : if (transport->opts.in_capsule_data_size < SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE) {
1588 [ - + - + ]: 693 : SPDK_DEBUGLOG(nvmf_tcp, "ICD %u is less than min required for admin/fabric commands (%u). "
1589 : : "Creating control messages list\n", transport->opts.in_capsule_data_size,
1590 : : SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE);
1591 : 693 : tgroup->control_msg_list = nvmf_tcp_control_msg_list_create(ttransport->tcp_opts.control_msg_num);
1592 [ - + ]: 693 : if (!tgroup->control_msg_list) {
1593 : 0 : goto cleanup;
1594 : : }
1595 : : }
1596 : :
1597 : 693 : tgroup->accel_channel = spdk_accel_get_io_channel();
1598 [ - + ]: 693 : if (spdk_unlikely(!tgroup->accel_channel)) {
1599 : 0 : SPDK_ERRLOG("Cannot create accel_channel for tgroup=%p\n", tgroup);
1600 : 0 : goto cleanup;
1601 : : }
1602 : :
1603 : 693 : TAILQ_INSERT_TAIL(&ttransport->poll_groups, tgroup, link);
1604 [ + + ]: 693 : if (ttransport->next_pg == NULL) {
1605 : 315 : ttransport->next_pg = tgroup;
1606 : : }
1607 : :
1608 [ + + ]: 693 : if (spdk_interrupt_mode_is_enabled()) {
1609 : 264 : rc = SPDK_SOCK_GROUP_REGISTER_INTERRUPT(tgroup->sock_group,
1610 : : SPDK_INTERRUPT_EVENT_IN | SPDK_INTERRUPT_EVENT_OUT, nvmf_tcp_poll_group_intr, &tgroup->group);
1611 [ - + ]: 264 : if (rc != 0) {
1612 : 0 : SPDK_ERRLOG("Failed to register interrupt for sock group\n");
1613 : 0 : goto cleanup;
1614 : : }
1615 : : }
1616 : :
1617 : 693 : return &tgroup->group;
1618 : :
1619 : 0 : cleanup:
1620 : 0 : nvmf_tcp_poll_group_destroy(&tgroup->group);
1621 : 0 : return NULL;
1622 : : }
1623 : :
1624 : : static struct spdk_nvmf_transport_poll_group *
1625 : 12324 : nvmf_tcp_get_optimal_poll_group(struct spdk_nvmf_qpair *qpair)
1626 : : {
1627 : : struct spdk_nvmf_tcp_transport *ttransport;
1628 : : struct spdk_nvmf_tcp_poll_group **pg;
1629 : : struct spdk_nvmf_tcp_qpair *tqpair;
1630 : 12324 : struct spdk_sock_group *group = NULL, *hint = NULL;
1631 : : int rc;
1632 : :
1633 : 12324 : ttransport = SPDK_CONTAINEROF(qpair->transport, struct spdk_nvmf_tcp_transport, transport);
1634 : :
1635 [ - + ]: 12324 : if (TAILQ_EMPTY(&ttransport->poll_groups)) {
1636 : 0 : return NULL;
1637 : : }
1638 : :
1639 : 12324 : pg = &ttransport->next_pg;
1640 [ - + ]: 12324 : assert(*pg != NULL);
1641 : 12324 : hint = (*pg)->sock_group;
1642 : :
1643 : 12324 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
1644 : 12324 : rc = spdk_sock_get_optimal_sock_group(tqpair->sock, &group, hint);
1645 [ - + ]: 12324 : if (rc != 0) {
1646 : 0 : return NULL;
1647 [ + + ]: 12324 : } else if (group != NULL) {
1648 : : /* Optimal poll group was found */
1649 : 6 : return spdk_sock_group_get_ctx(group);
1650 : : }
1651 : :
1652 : : /* The hint was used for optimal poll group, advance next_pg. */
1653 : 12318 : *pg = TAILQ_NEXT(*pg, link);
1654 [ + + ]: 12318 : if (*pg == NULL) {
1655 : 4915 : *pg = TAILQ_FIRST(&ttransport->poll_groups);
1656 : : }
1657 : :
1658 : 12318 : return spdk_sock_group_get_ctx(hint);
1659 : : }
1660 : :
1661 : : static void
1662 : 693 : nvmf_tcp_poll_group_destroy(struct spdk_nvmf_transport_poll_group *group)
1663 : : {
1664 : : struct spdk_nvmf_tcp_poll_group *tgroup, *next_tgroup;
1665 : : struct spdk_nvmf_tcp_transport *ttransport;
1666 : :
1667 : 693 : tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group);
1668 : 693 : spdk_sock_group_unregister_interrupt(tgroup->sock_group);
1669 : 693 : spdk_sock_group_close(&tgroup->sock_group);
1670 [ + - ]: 693 : if (tgroup->control_msg_list) {
1671 : 693 : nvmf_tcp_control_msg_list_free(tgroup->control_msg_list);
1672 : : }
1673 : :
1674 [ + - ]: 693 : if (tgroup->accel_channel) {
1675 : 693 : spdk_put_io_channel(tgroup->accel_channel);
1676 : : }
1677 : :
1678 [ - + ]: 693 : if (tgroup->group.transport == NULL) {
1679 : : /* Transport can be NULL when nvmf_tcp_poll_group_create()
1680 : : * calls this function directly in a failure path. */
1681 : 0 : free(tgroup);
1682 : 0 : return;
1683 : : }
1684 : :
1685 : 693 : ttransport = SPDK_CONTAINEROF(tgroup->group.transport, struct spdk_nvmf_tcp_transport, transport);
1686 : :
1687 : 693 : next_tgroup = TAILQ_NEXT(tgroup, link);
1688 [ + + ]: 693 : TAILQ_REMOVE(&ttransport->poll_groups, tgroup, link);
1689 [ + + ]: 693 : if (next_tgroup == NULL) {
1690 : 413 : next_tgroup = TAILQ_FIRST(&ttransport->poll_groups);
1691 : : }
1692 [ + + ]: 693 : if (ttransport->next_pg == tgroup) {
1693 : 442 : ttransport->next_pg = next_tgroup;
1694 : : }
1695 : :
1696 : 693 : free(tgroup);
1697 : : }
1698 : :
1699 : : static void
1700 : 92197136 : nvmf_tcp_qpair_set_recv_state(struct spdk_nvmf_tcp_qpair *tqpair,
1701 : : enum nvme_tcp_pdu_recv_state state)
1702 : : {
1703 [ + + ]: 92197136 : if (tqpair->recv_state == state) {
1704 : 2333 : SPDK_ERRLOG("The recv state of tqpair=%p is same with the state(%d) to be set\n",
1705 : : tqpair, state);
1706 : 2333 : return;
1707 : : }
1708 : :
1709 [ + + ]: 92194803 : if (spdk_unlikely(state == NVME_TCP_PDU_RECV_STATE_QUIESCING)) {
1710 [ + + + - ]: 12270 : if (tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH && tqpair->pdu_in_progress) {
1711 : 12201 : SLIST_INSERT_HEAD(&tqpair->tcp_pdu_free_queue, tqpair->pdu_in_progress, slist);
1712 : 12201 : tqpair->tcp_pdu_working_count--;
1713 : : }
1714 : : }
1715 : :
1716 [ + + ]: 92194803 : if (spdk_unlikely(state == NVME_TCP_PDU_RECV_STATE_ERROR)) {
1717 [ - + ]: 12141 : assert(tqpair->tcp_pdu_working_count == 0);
1718 : : }
1719 : :
1720 [ + + ]: 92194803 : if (tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_REQ) {
1721 : : /* When leaving the await req state, move the qpair to the main list */
1722 [ + + ]: 20231781 : TAILQ_REMOVE(&tqpair->group->await_req, tqpair, link);
1723 : 20231781 : TAILQ_INSERT_TAIL(&tqpair->group->qpairs, tqpair, link);
1724 [ + + ]: 71963022 : } else if (state == NVME_TCP_PDU_RECV_STATE_AWAIT_REQ) {
1725 [ + + ]: 20231781 : TAILQ_REMOVE(&tqpair->group->qpairs, tqpair, link);
1726 : 20231781 : TAILQ_INSERT_TAIL(&tqpair->group->await_req, tqpair, link);
1727 : : }
1728 : :
1729 [ - + - + ]: 92194803 : SPDK_DEBUGLOG(nvmf_tcp, "tqpair(%p) recv state=%d\n", tqpair, state);
1730 : 92194803 : tqpair->recv_state = state;
1731 : :
1732 [ + + + + ]: 92194803 : spdk_trace_record(TRACE_TCP_QP_RCV_STATE_CHANGE, tqpair->qpair.trace_id, 0, 0,
1733 : : (uint64_t)tqpair->recv_state);
1734 : : }
1735 : :
1736 : : static int
1737 : 0 : nvmf_tcp_qpair_handle_timeout(void *ctx)
1738 : : {
1739 : 0 : struct spdk_nvmf_tcp_qpair *tqpair = ctx;
1740 : :
1741 [ # # ]: 0 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_ERROR);
1742 : :
1743 : 0 : SPDK_ERRLOG("No pdu coming for tqpair=%p within %d seconds\n", tqpair,
1744 : : SPDK_NVME_TCP_QPAIR_EXIT_TIMEOUT);
1745 : :
1746 : 0 : nvmf_tcp_qpair_disconnect(tqpair);
1747 : 0 : return SPDK_POLLER_BUSY;
1748 : : }
1749 : :
1750 : : static void
1751 : 0 : nvmf_tcp_send_c2h_term_req_complete(void *cb_arg)
1752 : : {
1753 : 0 : struct spdk_nvmf_tcp_qpair *tqpair = (struct spdk_nvmf_tcp_qpair *)cb_arg;
1754 : :
1755 [ # # ]: 0 : if (!tqpair->timeout_poller) {
1756 : 0 : tqpair->timeout_poller = SPDK_POLLER_REGISTER(nvmf_tcp_qpair_handle_timeout, tqpair,
1757 : : SPDK_NVME_TCP_QPAIR_EXIT_TIMEOUT * 1000000);
1758 : : }
1759 : 0 : }
1760 : :
1761 : : static void
1762 : 45 : nvmf_tcp_send_c2h_term_req(struct spdk_nvmf_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu,
1763 : : enum spdk_nvme_tcp_term_req_fes fes, uint32_t error_offset)
1764 : : {
1765 : : struct nvme_tcp_pdu *rsp_pdu;
1766 : : struct spdk_nvme_tcp_term_req_hdr *c2h_term_req;
1767 : 45 : uint32_t c2h_term_req_hdr_len = sizeof(*c2h_term_req);
1768 : : uint32_t copy_len;
1769 : :
1770 : 45 : rsp_pdu = tqpair->mgmt_pdu;
1771 : :
1772 : 45 : c2h_term_req = &rsp_pdu->hdr.term_req;
1773 : 45 : c2h_term_req->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ;
1774 : 45 : c2h_term_req->common.hlen = c2h_term_req_hdr_len;
1775 : 45 : c2h_term_req->fes = fes;
1776 : :
1777 [ + + - + ]: 45 : if ((fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD) ||
1778 : : (fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER)) {
1779 : 36 : DSET32(&c2h_term_req->fei, error_offset);
1780 : : }
1781 : :
1782 [ + + ]: 45 : copy_len = spdk_min(pdu->hdr.common.hlen, SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE);
1783 : :
1784 : : /* Copy the error info into the buffer */
1785 [ - + - + ]: 45 : memcpy((uint8_t *)rsp_pdu->hdr.raw + c2h_term_req_hdr_len, pdu->hdr.raw, copy_len);
1786 : 45 : nvme_tcp_pdu_set_data(rsp_pdu, (uint8_t *)rsp_pdu->hdr.raw + c2h_term_req_hdr_len, copy_len);
1787 : :
1788 : : /* Contain the header of the wrong received pdu */
1789 : 45 : c2h_term_req->common.plen = c2h_term_req->common.hlen + copy_len;
1790 : 45 : tqpair->wait_terminate = true;
1791 : 45 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
1792 : 45 : nvmf_tcp_qpair_write_mgmt_pdu(tqpair, nvmf_tcp_send_c2h_term_req_complete, tqpair);
1793 : 45 : }
1794 : :
1795 : : static void
1796 : 21651713 : nvmf_tcp_capsule_cmd_hdr_handle(struct spdk_nvmf_tcp_transport *ttransport,
1797 : : struct spdk_nvmf_tcp_qpair *tqpair,
1798 : : struct nvme_tcp_pdu *pdu)
1799 : : {
1800 : : struct spdk_nvmf_tcp_req *tcp_req;
1801 : :
1802 [ - + ]: 21651713 : assert(pdu->psh_valid_bytes == pdu->psh_len);
1803 [ - + ]: 21651713 : assert(pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD);
1804 : :
1805 : 21651713 : tcp_req = nvmf_tcp_req_get(tqpair);
1806 [ + + ]: 21651713 : if (!tcp_req) {
1807 : : /* Directly return and make the allocation retry again. This can happen if we're
1808 : : * using asynchronous writes to send the response to the host or when releasing
1809 : : * zero-copy buffers after a response has been sent. In both cases, the host might
1810 : : * receive the response before we've finished processing the request and is free to
1811 : : * send another one.
1812 : : */
1813 [ - + ]: 545282 : if (tqpair->state_cntr[TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST] > 0 ||
1814 [ # # ]: 0 : tqpair->state_cntr[TCP_REQUEST_STATE_AWAITING_ZCOPY_RELEASE] > 0) {
1815 : 545282 : return;
1816 : : }
1817 : :
1818 : : /* The host sent more commands than the maximum queue depth. */
1819 : 0 : SPDK_ERRLOG("Cannot allocate tcp_req on tqpair=%p\n", tqpair);
1820 : 0 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
1821 : 0 : return;
1822 : : }
1823 : :
1824 : 21106431 : pdu->req = tcp_req;
1825 [ - + ]: 21106431 : assert(tcp_req->state == TCP_REQUEST_STATE_NEW);
1826 : 21106431 : nvmf_tcp_req_process(ttransport, tcp_req);
1827 : : }
1828 : :
1829 : : static void
1830 : 8116412 : nvmf_tcp_capsule_cmd_payload_handle(struct spdk_nvmf_tcp_transport *ttransport,
1831 : : struct spdk_nvmf_tcp_qpair *tqpair,
1832 : : struct nvme_tcp_pdu *pdu)
1833 : : {
1834 : : struct spdk_nvmf_tcp_req *tcp_req;
1835 : : struct spdk_nvme_tcp_cmd *capsule_cmd;
1836 : 8116412 : uint32_t error_offset = 0;
1837 : : enum spdk_nvme_tcp_term_req_fes fes;
1838 : : struct spdk_nvme_cpl *rsp;
1839 : :
1840 : 8116412 : capsule_cmd = &pdu->hdr.capsule_cmd;
1841 : 8116412 : tcp_req = pdu->req;
1842 [ - + ]: 8116412 : assert(tcp_req != NULL);
1843 : :
1844 : : /* Zero-copy requests don't support ICD */
1845 [ - + ]: 8116412 : assert(!spdk_nvmf_request_using_zcopy(&tcp_req->req));
1846 : :
1847 [ - + ]: 8116412 : if (capsule_cmd->common.pdo > SPDK_NVME_TCP_PDU_PDO_MAX_OFFSET) {
1848 : 0 : SPDK_ERRLOG("Expected ICReq capsule_cmd pdu offset <= %d, got %c\n",
1849 : : SPDK_NVME_TCP_PDU_PDO_MAX_OFFSET, capsule_cmd->common.pdo);
1850 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1851 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, pdo);
1852 : 0 : goto err;
1853 : : }
1854 : :
1855 : 8116412 : rsp = &tcp_req->req.rsp->nvme_cpl;
1856 [ + + ]: 8116412 : if (spdk_unlikely(rsp->status.sc == SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR)) {
1857 : 730 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_COMPLETE);
1858 : : } else {
1859 : 8115682 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_EXECUTE);
1860 : : }
1861 : :
1862 : 8116412 : nvmf_tcp_req_process(ttransport, tcp_req);
1863 : :
1864 : 8116412 : return;
1865 : 0 : err:
1866 : 0 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
1867 : : }
1868 : :
1869 : : static void
1870 : 769435 : nvmf_tcp_h2c_data_hdr_handle(struct spdk_nvmf_tcp_transport *ttransport,
1871 : : struct spdk_nvmf_tcp_qpair *tqpair,
1872 : : struct nvme_tcp_pdu *pdu)
1873 : : {
1874 : : struct spdk_nvmf_tcp_req *tcp_req;
1875 : 769435 : uint32_t error_offset = 0;
1876 : 769435 : enum spdk_nvme_tcp_term_req_fes fes = 0;
1877 : : struct spdk_nvme_tcp_h2c_data_hdr *h2c_data;
1878 : :
1879 : 769435 : h2c_data = &pdu->hdr.h2c_data;
1880 : :
1881 [ - + - + ]: 769435 : SPDK_DEBUGLOG(nvmf_tcp, "tqpair=%p, r2t_info: datao=%u, datal=%u, cccid=%u, ttag=%u\n",
1882 : : tqpair, h2c_data->datao, h2c_data->datal, h2c_data->cccid, h2c_data->ttag);
1883 : :
1884 [ - + ]: 769435 : if (h2c_data->ttag > tqpair->resource_count) {
1885 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "ttag %u is larger than allowed %u.\n", h2c_data->ttag,
1886 : : tqpair->resource_count);
1887 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_PDU_SEQUENCE_ERROR;
1888 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_h2c_data_hdr, ttag);
1889 : 0 : goto err;
1890 : : }
1891 : :
1892 : 769435 : tcp_req = &tqpair->reqs[h2c_data->ttag - 1];
1893 : :
1894 [ + + - + ]: 769435 : if (spdk_unlikely(tcp_req->state != TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER &&
1895 : : tcp_req->state != TCP_REQUEST_STATE_AWAITING_R2T_ACK)) {
1896 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "tcp_req(%p), tqpair=%p, has error state in %d\n", tcp_req, tqpair,
1897 : : tcp_req->state);
1898 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
1899 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_h2c_data_hdr, ttag);
1900 : 0 : goto err;
1901 : : }
1902 : :
1903 [ - + ]: 769435 : if (spdk_unlikely(tcp_req->req.cmd->nvme_cmd.cid != h2c_data->cccid)) {
1904 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "tcp_req(%p), tqpair=%p, expected %u but %u for cccid.\n", tcp_req, tqpair,
1905 : : tcp_req->req.cmd->nvme_cmd.cid, h2c_data->cccid);
1906 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_PDU_SEQUENCE_ERROR;
1907 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_h2c_data_hdr, cccid);
1908 : 0 : goto err;
1909 : : }
1910 : :
1911 [ - + ]: 769435 : if (tcp_req->h2c_offset != h2c_data->datao) {
1912 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp,
1913 : : "tcp_req(%p), tqpair=%p, expected data offset %u, but data offset is %u\n",
1914 : : tcp_req, tqpair, tcp_req->h2c_offset, h2c_data->datao);
1915 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_OUT_OF_RANGE;
1916 : 0 : goto err;
1917 : : }
1918 : :
1919 [ - + ]: 769435 : if ((h2c_data->datao + h2c_data->datal) > tcp_req->req.length) {
1920 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp,
1921 : : "tcp_req(%p), tqpair=%p, (datao=%u + datal=%u) exceeds requested length=%u\n",
1922 : : tcp_req, tqpair, h2c_data->datao, h2c_data->datal, tcp_req->req.length);
1923 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_OUT_OF_RANGE;
1924 : 0 : goto err;
1925 : : }
1926 : :
1927 : 769435 : pdu->req = tcp_req;
1928 : :
1929 [ - + ]: 769435 : if (spdk_unlikely(tcp_req->req.dif_enabled)) {
1930 : 0 : pdu->dif_ctx = &tcp_req->req.dif.dif_ctx;
1931 : : }
1932 : :
1933 : 769435 : nvme_tcp_pdu_set_data_buf(pdu, tcp_req->req.iov, tcp_req->req.iovcnt,
1934 : : h2c_data->datao, h2c_data->datal);
1935 : 769435 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
1936 : 769435 : return;
1937 : :
1938 : 0 : err:
1939 : 0 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
1940 : : }
1941 : :
1942 : : static void
1943 : 20064890 : nvmf_tcp_send_capsule_resp_pdu(struct spdk_nvmf_tcp_req *tcp_req,
1944 : : struct spdk_nvmf_tcp_qpair *tqpair)
1945 : : {
1946 : : struct nvme_tcp_pdu *rsp_pdu;
1947 : : struct spdk_nvme_tcp_rsp *capsule_resp;
1948 : :
1949 [ - + - + ]: 20064890 : SPDK_DEBUGLOG(nvmf_tcp, "enter, tqpair=%p\n", tqpair);
1950 : :
1951 : 20064890 : rsp_pdu = nvmf_tcp_req_pdu_init(tcp_req);
1952 [ - + ]: 20064890 : assert(rsp_pdu != NULL);
1953 : :
1954 : 20064890 : capsule_resp = &rsp_pdu->hdr.capsule_resp;
1955 : 20064890 : capsule_resp->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_CAPSULE_RESP;
1956 : 20064890 : capsule_resp->common.plen = capsule_resp->common.hlen = sizeof(*capsule_resp);
1957 : 20064890 : capsule_resp->rccqe = tcp_req->req.rsp->nvme_cpl;
1958 [ + + + + ]: 20064890 : if (tqpair->host_hdgst_enable) {
1959 : 663080 : capsule_resp->common.flags |= SPDK_NVME_TCP_CH_FLAGS_HDGSTF;
1960 : 663080 : capsule_resp->common.plen += SPDK_NVME_TCP_DIGEST_LEN;
1961 : : }
1962 : :
1963 : 20064890 : nvmf_tcp_qpair_write_req_pdu(tqpair, tcp_req, nvmf_tcp_request_free, tcp_req);
1964 : 20064890 : }
1965 : :
1966 : : static void
1967 : 11112926 : nvmf_tcp_pdu_c2h_data_complete(void *cb_arg)
1968 : : {
1969 : 11112926 : struct spdk_nvmf_tcp_req *tcp_req = cb_arg;
1970 : 11112926 : struct spdk_nvmf_tcp_qpair *tqpair = SPDK_CONTAINEROF(tcp_req->req.qpair,
1971 : : struct spdk_nvmf_tcp_qpair, qpair);
1972 : :
1973 [ - + ]: 11112926 : assert(tqpair != NULL);
1974 : :
1975 [ + + ]: 11112926 : if (spdk_unlikely(tcp_req->pdu->rw_offset < tcp_req->req.length)) {
1976 [ - + - + ]: 217828 : SPDK_DEBUGLOG(nvmf_tcp, "sending another C2H part, offset %u length %u\n", tcp_req->pdu->rw_offset,
1977 : : tcp_req->req.length);
1978 : 217828 : _nvmf_tcp_send_c2h_data(tqpair, tcp_req);
1979 : 217828 : return;
1980 : : }
1981 : :
1982 [ + + ]: 10895098 : if (tcp_req->pdu->hdr.c2h_data.common.flags & SPDK_NVME_TCP_C2H_DATA_FLAGS_SUCCESS) {
1983 : 157370 : nvmf_tcp_request_free(tcp_req);
1984 : : } else {
1985 : 10737728 : nvmf_tcp_send_capsule_resp_pdu(tcp_req, tqpair);
1986 : : }
1987 : : }
1988 : :
1989 : : static void
1990 : 769547 : nvmf_tcp_r2t_complete(void *cb_arg)
1991 : : {
1992 : 769547 : struct spdk_nvmf_tcp_req *tcp_req = cb_arg;
1993 : : struct spdk_nvmf_tcp_transport *ttransport;
1994 : :
1995 : 769547 : ttransport = SPDK_CONTAINEROF(tcp_req->req.qpair->transport,
1996 : : struct spdk_nvmf_tcp_transport, transport);
1997 : :
1998 : 769547 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER);
1999 : :
2000 [ + + ]: 769547 : if (tcp_req->h2c_offset == tcp_req->req.length) {
2001 : 610 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_EXECUTE);
2002 : 610 : nvmf_tcp_req_process(ttransport, tcp_req);
2003 : : }
2004 : 769547 : }
2005 : :
2006 : : static void
2007 : 769568 : nvmf_tcp_send_r2t_pdu(struct spdk_nvmf_tcp_qpair *tqpair,
2008 : : struct spdk_nvmf_tcp_req *tcp_req)
2009 : : {
2010 : : struct nvme_tcp_pdu *rsp_pdu;
2011 : : struct spdk_nvme_tcp_r2t_hdr *r2t;
2012 : :
2013 : 769568 : rsp_pdu = nvmf_tcp_req_pdu_init(tcp_req);
2014 [ - + ]: 769568 : assert(rsp_pdu != NULL);
2015 : :
2016 : 769568 : r2t = &rsp_pdu->hdr.r2t;
2017 : 769568 : r2t->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_R2T;
2018 : 769568 : r2t->common.plen = r2t->common.hlen = sizeof(*r2t);
2019 : :
2020 [ - + - + ]: 769568 : if (tqpair->host_hdgst_enable) {
2021 : 0 : r2t->common.flags |= SPDK_NVME_TCP_CH_FLAGS_HDGSTF;
2022 : 0 : r2t->common.plen += SPDK_NVME_TCP_DIGEST_LEN;
2023 : : }
2024 : :
2025 : 769568 : r2t->cccid = tcp_req->req.cmd->nvme_cmd.cid;
2026 : 769568 : r2t->ttag = tcp_req->ttag;
2027 : 769568 : r2t->r2to = tcp_req->h2c_offset;
2028 : 769568 : r2t->r2tl = tcp_req->req.length;
2029 : :
2030 : 769568 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_AWAITING_R2T_ACK);
2031 : :
2032 [ - + - + ]: 769568 : SPDK_DEBUGLOG(nvmf_tcp,
2033 : : "tcp_req(%p) on tqpair(%p), r2t_info: cccid=%u, ttag=%u, r2to=%u, r2tl=%u\n",
2034 : : tcp_req, tqpair, r2t->cccid, r2t->ttag, r2t->r2to, r2t->r2tl);
2035 : 769568 : nvmf_tcp_qpair_write_req_pdu(tqpair, tcp_req, nvmf_tcp_r2t_complete, tcp_req);
2036 : 769568 : }
2037 : :
2038 : : static void
2039 : 769428 : nvmf_tcp_h2c_data_payload_handle(struct spdk_nvmf_tcp_transport *ttransport,
2040 : : struct spdk_nvmf_tcp_qpair *tqpair,
2041 : : struct nvme_tcp_pdu *pdu)
2042 : : {
2043 : : struct spdk_nvmf_tcp_req *tcp_req;
2044 : : struct spdk_nvme_cpl *rsp;
2045 : :
2046 : 769428 : tcp_req = pdu->req;
2047 [ - + ]: 769428 : assert(tcp_req != NULL);
2048 : :
2049 [ - + - + ]: 769428 : SPDK_DEBUGLOG(nvmf_tcp, "enter\n");
2050 : :
2051 : 769428 : tcp_req->h2c_offset += pdu->data_len;
2052 : :
2053 : : /* Wait for all of the data to arrive AND for the initial R2T PDU send to be
2054 : : * acknowledged before moving on. */
2055 [ + - ]: 769428 : if (tcp_req->h2c_offset == tcp_req->req.length &&
2056 [ + + ]: 769428 : tcp_req->state == TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER) {
2057 : : /* After receiving all the h2c data, we need to check whether there is
2058 : : * transient transport error */
2059 : 768818 : rsp = &tcp_req->req.rsp->nvme_cpl;
2060 [ + + ]: 768818 : if (spdk_unlikely(rsp->status.sc == SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR)) {
2061 : 1842 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_COMPLETE);
2062 : : } else {
2063 : 766976 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_EXECUTE);
2064 : : }
2065 : 768818 : nvmf_tcp_req_process(ttransport, tcp_req);
2066 : : }
2067 : 769428 : }
2068 : :
2069 : : static void
2070 : 0 : nvmf_tcp_h2c_term_req_dump(struct spdk_nvme_tcp_term_req_hdr *h2c_term_req)
2071 : : {
2072 : 0 : SPDK_ERRLOG("Error info of pdu(%p): %s\n", h2c_term_req,
2073 : : spdk_nvmf_tcp_term_req_fes_str[h2c_term_req->fes]);
2074 [ # # ]: 0 : if ((h2c_term_req->fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD) ||
2075 [ # # ]: 0 : (h2c_term_req->fes == SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER)) {
2076 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "The offset from the start of the PDU header is %u\n",
2077 : : DGET32(h2c_term_req->fei));
2078 : : }
2079 : 0 : }
2080 : :
2081 : : static void
2082 : 0 : nvmf_tcp_h2c_term_req_hdr_handle(struct spdk_nvmf_tcp_qpair *tqpair,
2083 : : struct nvme_tcp_pdu *pdu)
2084 : : {
2085 : 0 : struct spdk_nvme_tcp_term_req_hdr *h2c_term_req = &pdu->hdr.term_req;
2086 : 0 : uint32_t error_offset = 0;
2087 : : enum spdk_nvme_tcp_term_req_fes fes;
2088 : :
2089 [ # # ]: 0 : if (h2c_term_req->fes > SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER) {
2090 : 0 : SPDK_ERRLOG("Fatal Error Status(FES) is unknown for h2c_term_req pdu=%p\n", pdu);
2091 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2092 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_term_req_hdr, fes);
2093 : 0 : goto end;
2094 : : }
2095 : :
2096 : : /* set the data buffer */
2097 : 0 : nvme_tcp_pdu_set_data(pdu, (uint8_t *)pdu->hdr.raw + h2c_term_req->common.hlen,
2098 : 0 : h2c_term_req->common.plen - h2c_term_req->common.hlen);
2099 : 0 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
2100 : 0 : return;
2101 : 0 : end:
2102 : 0 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
2103 : : }
2104 : :
2105 : : static void
2106 : 0 : nvmf_tcp_h2c_term_req_payload_handle(struct spdk_nvmf_tcp_qpair *tqpair,
2107 : : struct nvme_tcp_pdu *pdu)
2108 : : {
2109 : 0 : struct spdk_nvme_tcp_term_req_hdr *h2c_term_req = &pdu->hdr.term_req;
2110 : :
2111 : 0 : nvmf_tcp_h2c_term_req_dump(h2c_term_req);
2112 : 0 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2113 : 0 : }
2114 : :
2115 : : static void
2116 : 8885840 : _nvmf_tcp_pdu_payload_handle(struct spdk_nvmf_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu)
2117 : : {
2118 : 8885840 : struct spdk_nvmf_tcp_transport *ttransport = SPDK_CONTAINEROF(tqpair->qpair.transport,
2119 : : struct spdk_nvmf_tcp_transport, transport);
2120 : :
2121 [ + + - - ]: 8885840 : switch (pdu->hdr.common.pdu_type) {
2122 : 8116412 : case SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD:
2123 : 8116412 : nvmf_tcp_capsule_cmd_payload_handle(ttransport, tqpair, pdu);
2124 : 8116412 : break;
2125 : 769428 : case SPDK_NVME_TCP_PDU_TYPE_H2C_DATA:
2126 : 769428 : nvmf_tcp_h2c_data_payload_handle(ttransport, tqpair, pdu);
2127 : 769428 : break;
2128 : :
2129 : 0 : case SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ:
2130 : 0 : nvmf_tcp_h2c_term_req_payload_handle(tqpair, pdu);
2131 : 0 : break;
2132 : :
2133 : 0 : default:
2134 : : /* The code should not go to here */
2135 : 0 : SPDK_ERRLOG("ERROR pdu type %d\n", pdu->hdr.common.pdu_type);
2136 : 0 : break;
2137 : : }
2138 : 8885840 : SLIST_INSERT_HEAD(&tqpair->tcp_pdu_free_queue, pdu, slist);
2139 : 8885840 : tqpair->tcp_pdu_working_count--;
2140 : 8885840 : }
2141 : :
2142 : : static inline void
2143 : 2575 : nvmf_tcp_req_set_cpl(struct spdk_nvmf_tcp_req *treq, int sct, int sc)
2144 : : {
2145 : 2575 : treq->req.rsp->nvme_cpl.status.sct = sct;
2146 : 2575 : treq->req.rsp->nvme_cpl.status.sc = sc;
2147 : 2575 : treq->req.rsp->nvme_cpl.cid = treq->req.cmd->nvme_cmd.cid;
2148 : 2575 : }
2149 : :
2150 : : static void
2151 : 806394 : data_crc32_calc_done(void *cb_arg, int status)
2152 : : {
2153 : 806394 : struct nvme_tcp_pdu *pdu = cb_arg;
2154 : 806394 : struct spdk_nvmf_tcp_qpair *tqpair = pdu->qpair;
2155 : :
2156 : : /* async crc32 calculation is failed and use direct calculation to check */
2157 [ - + ]: 806394 : if (spdk_unlikely(status)) {
2158 : 0 : SPDK_ERRLOG("Data digest on tqpair=(%p) with pdu=%p failed to be calculated asynchronously\n",
2159 : : tqpair, pdu);
2160 : 0 : pdu->data_digest_crc32 = nvme_tcp_pdu_calc_data_digest(pdu);
2161 : : }
2162 : 806394 : pdu->data_digest_crc32 ^= SPDK_CRC32C_XOR;
2163 [ + + ]: 806394 : if (!MATCH_DIGEST_WORD(pdu->data_digest, pdu->data_digest_crc32)) {
2164 : 2572 : SPDK_ERRLOG("Data digest error on tqpair=(%p) with pdu=%p\n", tqpair, pdu);
2165 [ - + ]: 2572 : assert(pdu->req != NULL);
2166 : 2572 : nvmf_tcp_req_set_cpl(pdu->req, SPDK_NVME_SCT_GENERIC,
2167 : : SPDK_NVME_SC_COMMAND_TRANSIENT_TRANSPORT_ERROR);
2168 : : }
2169 : 806394 : _nvmf_tcp_pdu_payload_handle(tqpair, pdu);
2170 : 806394 : }
2171 : :
2172 : : static void
2173 : 8885840 : nvmf_tcp_pdu_payload_handle(struct spdk_nvmf_tcp_qpair *tqpair, struct nvme_tcp_pdu *pdu)
2174 : : {
2175 : 8885840 : int rc = 0;
2176 [ - + ]: 8885840 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
2177 : 8885840 : tqpair->pdu_in_progress = NULL;
2178 : 8885840 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
2179 [ - + - + ]: 8885840 : SPDK_DEBUGLOG(nvmf_tcp, "enter\n");
2180 : : /* check data digest if need */
2181 [ - + + + ]: 8885840 : if (pdu->ddgst_enable) {
2182 [ + + + - : 806394 : if (tqpair->qpair.qid != 0 && !pdu->dif_ctx && tqpair->group &&
+ - ]
2183 [ + - ]: 806174 : (pdu->data_len % SPDK_NVME_TCP_DIGEST_ALIGNMENT == 0)) {
2184 : 806174 : rc = spdk_accel_submit_crc32cv(tqpair->group->accel_channel, &pdu->data_digest_crc32, pdu->data_iov,
2185 : : pdu->data_iovcnt, 0, data_crc32_calc_done, pdu);
2186 [ + - ]: 806174 : if (spdk_likely(rc == 0)) {
2187 : 806174 : return;
2188 : : }
2189 : : } else {
2190 : 220 : pdu->data_digest_crc32 = nvme_tcp_pdu_calc_data_digest(pdu);
2191 : : }
2192 : 220 : data_crc32_calc_done(pdu, rc);
2193 : : } else {
2194 : 8079446 : _nvmf_tcp_pdu_payload_handle(tqpair, pdu);
2195 : : }
2196 : : }
2197 : :
2198 : : static void
2199 : 24596 : nvmf_tcp_send_icresp_complete(void *cb_arg)
2200 : : {
2201 : 24596 : struct spdk_nvmf_tcp_qpair *tqpair = cb_arg;
2202 : :
2203 : 24596 : nvmf_tcp_qpair_set_state(tqpair, NVME_TCP_QPAIR_STATE_RUNNING);
2204 : 24596 : }
2205 : :
2206 : : static void
2207 : 12307 : nvmf_tcp_icreq_handle(struct spdk_nvmf_tcp_transport *ttransport,
2208 : : struct spdk_nvmf_tcp_qpair *tqpair,
2209 : : struct nvme_tcp_pdu *pdu)
2210 : : {
2211 : 12307 : struct spdk_nvme_tcp_ic_req *ic_req = &pdu->hdr.ic_req;
2212 : : struct nvme_tcp_pdu *rsp_pdu;
2213 : : struct spdk_nvme_tcp_ic_resp *ic_resp;
2214 : 12307 : uint32_t error_offset = 0;
2215 : : enum spdk_nvme_tcp_term_req_fes fes;
2216 : :
2217 : : /* Only PFV 0 is defined currently */
2218 [ + + ]: 12307 : if (ic_req->pfv != 0) {
2219 : 6 : SPDK_ERRLOG("Expected ICReq PFV %u, got %u\n", 0u, ic_req->pfv);
2220 : 6 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2221 : 6 : error_offset = offsetof(struct spdk_nvme_tcp_ic_req, pfv);
2222 : 6 : goto end;
2223 : : }
2224 : :
2225 : : /* This value is 0’s based value in units of dwords should not be larger than SPDK_NVME_TCP_HPDA_MAX */
2226 [ - + ]: 12301 : if (ic_req->hpda > SPDK_NVME_TCP_HPDA_MAX) {
2227 : 0 : SPDK_ERRLOG("ICReq HPDA out of range 0 to 31, got %u\n", ic_req->hpda);
2228 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2229 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_ic_req, hpda);
2230 : 0 : goto end;
2231 : : }
2232 : :
2233 : : /* MAXR2T is 0's based */
2234 [ - + - + ]: 12301 : SPDK_DEBUGLOG(nvmf_tcp, "maxr2t =%u\n", (ic_req->maxr2t + 1u));
2235 : :
2236 : 12301 : tqpair->host_hdgst_enable = ic_req->dgst.bits.hdgst_enable ? true : false;
2237 [ + + + + ]: 12301 : if (!tqpair->host_hdgst_enable) {
2238 : 12205 : tqpair->recv_buf_size -= SPDK_NVME_TCP_DIGEST_LEN * SPDK_NVMF_TCP_RECV_BUF_SIZE_FACTOR;
2239 : : }
2240 : :
2241 : 12301 : tqpair->host_ddgst_enable = ic_req->dgst.bits.ddgst_enable ? true : false;
2242 [ + + + + ]: 12301 : if (!tqpair->host_ddgst_enable) {
2243 : 12081 : tqpair->recv_buf_size -= SPDK_NVME_TCP_DIGEST_LEN * SPDK_NVMF_TCP_RECV_BUF_SIZE_FACTOR;
2244 : : }
2245 : :
2246 : 12301 : tqpair->recv_buf_size = spdk_max(tqpair->recv_buf_size, MIN_SOCK_PIPE_SIZE);
2247 : : /* Now that we know whether digests are enabled, properly size the receive buffer */
2248 [ - + ]: 12301 : if (spdk_sock_set_recvbuf(tqpair->sock, tqpair->recv_buf_size) < 0) {
2249 : 0 : SPDK_WARNLOG("Unable to allocate enough memory for receive buffer on tqpair=%p with size=%d\n",
2250 : : tqpair,
2251 : : tqpair->recv_buf_size);
2252 : : /* Not fatal. */
2253 : : }
2254 : :
2255 : 12301 : tqpair->cpda = spdk_min(ic_req->hpda, SPDK_NVME_TCP_CPDA_MAX);
2256 [ - + - + ]: 12301 : SPDK_DEBUGLOG(nvmf_tcp, "cpda of tqpair=(%p) is : %u\n", tqpair, tqpair->cpda);
2257 : :
2258 : 12301 : rsp_pdu = tqpair->mgmt_pdu;
2259 : :
2260 : 12301 : ic_resp = &rsp_pdu->hdr.ic_resp;
2261 : 12301 : ic_resp->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_IC_RESP;
2262 : 12301 : ic_resp->common.hlen = ic_resp->common.plen = sizeof(*ic_resp);
2263 : 12301 : ic_resp->pfv = 0;
2264 : 12301 : ic_resp->cpda = tqpair->cpda;
2265 : 12301 : ic_resp->maxh2cdata = ttransport->transport.opts.max_io_size;
2266 [ - + ]: 12301 : ic_resp->dgst.bits.hdgst_enable = tqpair->host_hdgst_enable ? 1 : 0;
2267 [ - + ]: 12301 : ic_resp->dgst.bits.ddgst_enable = tqpair->host_ddgst_enable ? 1 : 0;
2268 : :
2269 [ - + - + : 12301 : SPDK_DEBUGLOG(nvmf_tcp, "host_hdgst_enable: %u\n", tqpair->host_hdgst_enable);
- - ]
2270 [ - + - + : 12301 : SPDK_DEBUGLOG(nvmf_tcp, "host_ddgst_enable: %u\n", tqpair->host_ddgst_enable);
- - ]
2271 : :
2272 : 12301 : nvmf_tcp_qpair_set_state(tqpair, NVME_TCP_QPAIR_STATE_INITIALIZING);
2273 : 12301 : nvmf_tcp_qpair_write_mgmt_pdu(tqpair, nvmf_tcp_send_icresp_complete, tqpair);
2274 : 12301 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
2275 : 12301 : return;
2276 : 6 : end:
2277 : 6 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
2278 : : }
2279 : :
2280 : : static void
2281 : 21013511 : nvmf_tcp_pdu_psh_handle(struct spdk_nvmf_tcp_qpair *tqpair,
2282 : : struct spdk_nvmf_tcp_transport *ttransport)
2283 : : {
2284 : : struct nvme_tcp_pdu *pdu;
2285 : : int rc;
2286 : 21013511 : uint32_t crc32c, error_offset = 0;
2287 : : enum spdk_nvme_tcp_term_req_fes fes;
2288 : :
2289 [ - + ]: 21013511 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH);
2290 : 21013511 : pdu = tqpair->pdu_in_progress;
2291 : :
2292 [ - + - + ]: 21013511 : SPDK_DEBUGLOG(nvmf_tcp, "pdu type of tqpair(%p) is %d\n", tqpair,
2293 : : pdu->hdr.common.pdu_type);
2294 : : /* check header digest if needed */
2295 [ - + + + ]: 21013511 : if (pdu->has_hdgst) {
2296 [ - + - + ]: 663115 : SPDK_DEBUGLOG(nvmf_tcp, "Compare the header of pdu=%p on tqpair=%p\n", pdu, tqpair);
2297 : 663115 : crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
2298 : 663115 : rc = MATCH_DIGEST_WORD((uint8_t *)pdu->hdr.raw + pdu->hdr.common.hlen, crc32c);
2299 [ - + ]: 663115 : if (rc == 0) {
2300 : 0 : SPDK_ERRLOG("Header digest error on tqpair=(%p) with pdu=%p\n", tqpair, pdu);
2301 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_HDGST_ERROR;
2302 : 0 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
2303 : 0 : return;
2304 : :
2305 : : }
2306 : : }
2307 : :
2308 [ + + + - : 21013511 : switch (pdu->hdr.common.pdu_type) {
- ]
2309 : 12298 : case SPDK_NVME_TCP_PDU_TYPE_IC_REQ:
2310 : 12298 : nvmf_tcp_icreq_handle(ttransport, tqpair, pdu);
2311 : 12298 : break;
2312 : 20231781 : case SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD:
2313 : 20231781 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_REQ);
2314 : 20231781 : break;
2315 : 769432 : case SPDK_NVME_TCP_PDU_TYPE_H2C_DATA:
2316 : 769432 : nvmf_tcp_h2c_data_hdr_handle(ttransport, tqpair, pdu);
2317 : 769432 : break;
2318 : :
2319 : 0 : case SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ:
2320 : 0 : nvmf_tcp_h2c_term_req_hdr_handle(tqpair, pdu);
2321 : 0 : break;
2322 : :
2323 : 0 : default:
2324 : 0 : SPDK_ERRLOG("Unexpected PDU type 0x%02x\n", tqpair->pdu_in_progress->hdr.common.pdu_type);
2325 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2326 : 0 : error_offset = 1;
2327 : 0 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
2328 : 0 : break;
2329 : : }
2330 : : }
2331 : :
2332 : : static void
2333 : 21013544 : nvmf_tcp_pdu_ch_handle(struct spdk_nvmf_tcp_qpair *tqpair)
2334 : : {
2335 : : struct nvme_tcp_pdu *pdu;
2336 : 21013544 : uint32_t error_offset = 0;
2337 : : enum spdk_nvme_tcp_term_req_fes fes;
2338 : : uint8_t expected_hlen, pdo;
2339 : 21013544 : bool plen_error = false, pdo_error = false;
2340 : :
2341 [ - + ]: 21013544 : assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH);
2342 : 21013544 : pdu = tqpair->pdu_in_progress;
2343 [ - + ]: 21013544 : assert(pdu);
2344 [ + + ]: 21013544 : if (pdu->hdr.common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_REQ) {
2345 [ + + ]: 12310 : if (tqpair->state != NVME_TCP_QPAIR_STATE_INVALID) {
2346 : 3 : SPDK_ERRLOG("Already received ICreq PDU, and reject this pdu=%p\n", pdu);
2347 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_PDU_SEQUENCE_ERROR;
2348 : 3 : goto err;
2349 : : }
2350 : 12307 : expected_hlen = sizeof(struct spdk_nvme_tcp_ic_req);
2351 [ + + ]: 12307 : if (pdu->hdr.common.plen != expected_hlen) {
2352 : 3 : plen_error = true;
2353 : : }
2354 : : } else {
2355 [ + + ]: 21001234 : if (tqpair->state != NVME_TCP_QPAIR_STATE_RUNNING) {
2356 : 3 : SPDK_ERRLOG("The TCP/IP connection is not negotiated\n");
2357 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_PDU_SEQUENCE_ERROR;
2358 : 3 : goto err;
2359 : : }
2360 : :
2361 [ + + + + ]: 21001231 : switch (pdu->hdr.common.pdu_type) {
2362 : 20231787 : case SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD:
2363 : 20231787 : expected_hlen = sizeof(struct spdk_nvme_tcp_cmd);
2364 : 20231787 : pdo = pdu->hdr.common.pdo;
2365 [ + + + + : 20231787 : if ((tqpair->cpda != 0) && (pdo % ((tqpair->cpda + 1) << 2) != 0)) {
- + + - ]
2366 : 3 : pdo_error = true;
2367 : 3 : break;
2368 : : }
2369 : :
2370 [ + + ]: 20231784 : if (pdu->hdr.common.plen < expected_hlen) {
2371 : 3 : plen_error = true;
2372 : : }
2373 : 20231784 : break;
2374 : 769438 : case SPDK_NVME_TCP_PDU_TYPE_H2C_DATA:
2375 : 769438 : expected_hlen = sizeof(struct spdk_nvme_tcp_h2c_data_hdr);
2376 : 769438 : pdo = pdu->hdr.common.pdo;
2377 [ + + + + : 769438 : if ((tqpair->cpda != 0) && (pdo % ((tqpair->cpda + 1) << 2) != 0)) {
- + + - ]
2378 : 3 : pdo_error = true;
2379 : 3 : break;
2380 : : }
2381 [ + + ]: 769435 : if (pdu->hdr.common.plen < expected_hlen) {
2382 : 3 : plen_error = true;
2383 : : }
2384 : 769435 : break;
2385 : :
2386 : 3 : case SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ:
2387 : 3 : expected_hlen = sizeof(struct spdk_nvme_tcp_term_req_hdr);
2388 [ - + ]: 3 : if ((pdu->hdr.common.plen <= expected_hlen) ||
2389 [ # # ]: 0 : (pdu->hdr.common.plen > SPDK_NVME_TCP_TERM_REQ_PDU_MAX_SIZE)) {
2390 : 3 : plen_error = true;
2391 : : }
2392 : 3 : break;
2393 : :
2394 : 3 : default:
2395 : 3 : SPDK_ERRLOG("Unexpected PDU type 0x%02x\n", pdu->hdr.common.pdu_type);
2396 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2397 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, pdu_type);
2398 : 3 : goto err;
2399 : : }
2400 : : }
2401 : :
2402 [ + + ]: 21013535 : if (pdu->hdr.common.hlen != expected_hlen) {
2403 : 3 : SPDK_ERRLOG("PDU type=0x%02x, Expected ICReq header length %u, got %u on tqpair=%p\n",
2404 : : pdu->hdr.common.pdu_type,
2405 : : expected_hlen, pdu->hdr.common.hlen, tqpair);
2406 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2407 : 3 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, hlen);
2408 : 3 : goto err;
2409 [ + + ]: 21013532 : } else if (pdo_error) {
2410 : 6 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2411 : 6 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, pdo);
2412 [ + + ]: 21013526 : } else if (plen_error) {
2413 : 12 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2414 : 12 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, plen);
2415 : 12 : goto err;
2416 : : } else {
2417 : 21013514 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH);
2418 [ - + ]: 21013514 : nvme_tcp_pdu_calc_psh_len(tqpair->pdu_in_progress, tqpair->host_hdgst_enable);
2419 : 21013514 : return;
2420 : : }
2421 : 30 : err:
2422 : 30 : nvmf_tcp_send_c2h_term_req(tqpair, pdu, fes, error_offset);
2423 : : }
2424 : :
2425 : : static int
2426 : 62385227 : nvmf_tcp_sock_process(struct spdk_nvmf_tcp_qpair *tqpair)
2427 : : {
2428 : 62385227 : int rc = 0;
2429 : : struct nvme_tcp_pdu *pdu;
2430 : : enum nvme_tcp_pdu_recv_state prev_state;
2431 : : uint32_t data_len;
2432 : 62385227 : struct spdk_nvmf_tcp_transport *ttransport = SPDK_CONTAINEROF(tqpair->qpair.transport,
2433 : : struct spdk_nvmf_tcp_transport, transport);
2434 : :
2435 : : /* The loop here is to allow for several back-to-back state changes. */
2436 : : do {
2437 : 133554120 : prev_state = tqpair->recv_state;
2438 [ - + - + ]: 133554120 : SPDK_DEBUGLOG(nvmf_tcp, "tqpair(%p) recv pdu entering state %d\n", tqpair, prev_state);
2439 : :
2440 : 133554120 : pdu = tqpair->pdu_in_progress;
2441 [ + + - + : 133554120 : assert(pdu != NULL ||
- - - - ]
2442 : : tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY ||
2443 : : tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_QUIESCING ||
2444 : : tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_ERROR);
2445 : :
2446 [ + + + + : 133554120 : switch (tqpair->recv_state) {
+ + + - ]
2447 : : /* Wait for the common header */
2448 : 21025766 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY:
2449 [ + + ]: 21025766 : if (!pdu) {
2450 : 8885840 : pdu = SLIST_FIRST(&tqpair->tcp_pdu_free_queue);
2451 [ - + ]: 8885840 : if (spdk_unlikely(!pdu)) {
2452 : 0 : return NVME_TCP_PDU_IN_PROGRESS;
2453 : : }
2454 : 8885840 : SLIST_REMOVE_HEAD(&tqpair->tcp_pdu_free_queue, slist);
2455 : 8885840 : tqpair->pdu_in_progress = pdu;
2456 : 8885840 : tqpair->tcp_pdu_working_count++;
2457 : : }
2458 [ - + ]: 21025766 : memset(pdu, 0, offsetof(struct nvme_tcp_pdu, qpair));
2459 : 21025766 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH);
2460 : : /* FALLTHROUGH */
2461 : 78584531 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH:
2462 [ - + ]: 78584531 : if (spdk_unlikely(tqpair->state == NVME_TCP_QPAIR_STATE_INITIALIZING)) {
2463 : 0 : return rc;
2464 : : }
2465 : :
2466 : 78584531 : rc = nvme_tcp_read_data(tqpair->sock,
2467 : 78584531 : sizeof(struct spdk_nvme_tcp_common_pdu_hdr) - pdu->ch_valid_bytes,
2468 : 78584531 : (void *)&pdu->hdr.common + pdu->ch_valid_bytes);
2469 [ + + ]: 78584531 : if (rc < 0) {
2470 [ - + - + ]: 12141 : SPDK_DEBUGLOG(nvmf_tcp, "will disconnect tqpair=%p\n", tqpair);
2471 : 12141 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2472 : 12141 : break;
2473 [ + + ]: 78572390 : } else if (rc > 0) {
2474 : 21013519 : pdu->ch_valid_bytes += rc;
2475 [ + + + + ]: 21013519 : spdk_trace_record(TRACE_TCP_READ_FROM_SOCKET_DONE, tqpair->qpair.trace_id, rc, 0);
2476 : : }
2477 : :
2478 [ + + ]: 78572390 : if (pdu->ch_valid_bytes < sizeof(struct spdk_nvme_tcp_common_pdu_hdr)) {
2479 : 57558879 : return NVME_TCP_PDU_IN_PROGRESS;
2480 : : }
2481 : :
2482 : : /* The command header of this PDU has now been read from the socket. */
2483 : 21013511 : nvmf_tcp_pdu_ch_handle(tqpair);
2484 : 21013511 : break;
2485 : : /* Wait for the pdu specific header */
2486 : 21060792 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH:
2487 : 21060792 : rc = nvme_tcp_read_data(tqpair->sock,
2488 : 21060792 : pdu->psh_len - pdu->psh_valid_bytes,
2489 : 21060792 : (void *)&pdu->hdr.raw + sizeof(struct spdk_nvme_tcp_common_pdu_hdr) + pdu->psh_valid_bytes);
2490 [ - + ]: 21060792 : if (rc < 0) {
2491 : 0 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2492 : 0 : break;
2493 [ + + ]: 21060792 : } else if (rc > 0) {
2494 [ + + + + ]: 21060093 : spdk_trace_record(TRACE_TCP_READ_FROM_SOCKET_DONE, tqpair->qpair.trace_id, rc, 0);
2495 : 21060093 : pdu->psh_valid_bytes += rc;
2496 : : }
2497 : :
2498 [ + + ]: 21060792 : if (pdu->psh_valid_bytes < pdu->psh_len) {
2499 : 47281 : return NVME_TCP_PDU_IN_PROGRESS;
2500 : : }
2501 : :
2502 : : /* All header(ch, psh, head digist) of this PDU has now been read from the socket. */
2503 : 21013511 : nvmf_tcp_pdu_psh_handle(tqpair, ttransport);
2504 : 21013511 : break;
2505 : : /* Wait for the req slot */
2506 : 21651710 : case NVME_TCP_PDU_RECV_STATE_AWAIT_REQ:
2507 : 21651710 : nvmf_tcp_capsule_cmd_hdr_handle(ttransport, tqpair, pdu);
2508 : 21651710 : break;
2509 : 11942836 : case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD:
2510 : : /* check whether the data is valid, if not we just return */
2511 [ - + ]: 11942836 : if (!pdu->data_len) {
2512 : 0 : return NVME_TCP_PDU_IN_PROGRESS;
2513 : : }
2514 : :
2515 : 11942836 : data_len = pdu->data_len;
2516 : : /* data digest */
2517 [ + - - + : 11942836 : if (spdk_unlikely((pdu->hdr.common.pdu_type != SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ) &&
+ + ]
2518 : : tqpair->host_ddgst_enable)) {
2519 : 1064131 : data_len += SPDK_NVME_TCP_DIGEST_LEN;
2520 : 1064131 : pdu->ddgst_enable = true;
2521 : : }
2522 : :
2523 : 11942836 : rc = nvme_tcp_read_payload_data(tqpair->sock, pdu);
2524 [ - + ]: 11942836 : if (rc < 0) {
2525 : 0 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2526 : 0 : break;
2527 : : }
2528 : 11942836 : pdu->rw_offset += rc;
2529 : :
2530 [ + + ]: 11942836 : if (pdu->rw_offset < data_len) {
2531 : 3056996 : return NVME_TCP_PDU_IN_PROGRESS;
2532 : : }
2533 : :
2534 : : /* Generate and insert DIF to whole data block received if DIF is enabled */
2535 [ - + - - ]: 8885840 : if (spdk_unlikely(pdu->dif_ctx != NULL) &&
2536 : 0 : spdk_dif_generate_stream(pdu->data_iov, pdu->data_iovcnt, 0, data_len,
2537 : : pdu->dif_ctx) != 0) {
2538 : 0 : SPDK_ERRLOG("DIF generate failed\n");
2539 : 0 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
2540 : 0 : break;
2541 : : }
2542 : :
2543 : : /* All of this PDU has now been read from the socket. */
2544 : 8885840 : nvmf_tcp_pdu_payload_handle(tqpair, pdu);
2545 : 8885840 : break;
2546 : 12157 : case NVME_TCP_PDU_RECV_STATE_QUIESCING:
2547 [ + + ]: 12157 : if (tqpair->tcp_pdu_working_count != 0) {
2548 : 16 : return NVME_TCP_PDU_IN_PROGRESS;
2549 : : }
2550 : 12141 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_ERROR);
2551 : 12141 : break;
2552 : 302094 : case NVME_TCP_PDU_RECV_STATE_ERROR:
2553 [ + + - + : 302094 : if (spdk_sock_is_connected(tqpair->sock) && tqpair->wait_terminate) {
- + ]
2554 : 0 : return NVME_TCP_PDU_IN_PROGRESS;
2555 : : }
2556 : 302094 : return NVME_TCP_PDU_FATAL;
2557 : 0 : default:
2558 : 0 : SPDK_ERRLOG("The state(%d) is invalid\n", tqpair->recv_state);
2559 : 0 : abort();
2560 : : break;
2561 : : }
2562 [ + + ]: 72588854 : } while (tqpair->recv_state != prev_state);
2563 : :
2564 : 1419961 : return rc;
2565 : : }
2566 : :
2567 : : static inline void *
2568 : 765 : nvmf_tcp_control_msg_get(struct spdk_nvmf_tcp_control_msg_list *list)
2569 : : {
2570 : : struct spdk_nvmf_tcp_control_msg *msg;
2571 : :
2572 [ - + ]: 765 : assert(list);
2573 : :
2574 : 765 : msg = STAILQ_FIRST(&list->free_msgs);
2575 [ - + ]: 765 : if (!msg) {
2576 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "Out of control messages\n");
2577 : 0 : return NULL;
2578 : : }
2579 [ - + ]: 765 : STAILQ_REMOVE_HEAD(&list->free_msgs, link);
2580 : 765 : return msg;
2581 : : }
2582 : :
2583 : : static inline void
2584 : 765 : nvmf_tcp_control_msg_put(struct spdk_nvmf_tcp_control_msg_list *list, void *_msg)
2585 : : {
2586 : 765 : struct spdk_nvmf_tcp_control_msg *msg = _msg;
2587 : :
2588 [ - + ]: 765 : assert(list);
2589 [ - + ]: 765 : STAILQ_INSERT_HEAD(&list->free_msgs, msg, link);
2590 : 765 : }
2591 : :
2592 : : static int
2593 : 20029853 : nvmf_tcp_req_parse_sgl(struct spdk_nvmf_tcp_req *tcp_req,
2594 : : struct spdk_nvmf_transport *transport,
2595 : : struct spdk_nvmf_transport_poll_group *group)
2596 : : {
2597 : 20029853 : struct spdk_nvmf_request *req = &tcp_req->req;
2598 : : struct spdk_nvme_cmd *cmd;
2599 : : struct spdk_nvme_sgl_descriptor *sgl;
2600 : : struct spdk_nvmf_tcp_poll_group *tgroup;
2601 : : enum spdk_nvme_tcp_term_req_fes fes;
2602 : : struct nvme_tcp_pdu *pdu;
2603 : : struct spdk_nvmf_tcp_qpair *tqpair;
2604 : 20029853 : uint32_t length, error_offset = 0;
2605 : :
2606 : 20029853 : cmd = &req->cmd->nvme_cmd;
2607 : 20029853 : sgl = &cmd->dptr.sgl1;
2608 : :
2609 [ + + ]: 20029853 : if (sgl->generic.type == SPDK_NVME_SGL_TYPE_TRANSPORT_DATA_BLOCK &&
2610 [ + - ]: 11913424 : sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_TRANSPORT) {
2611 : : /* get request length from sgl */
2612 : 11913424 : length = sgl->unkeyed.length;
2613 [ + + ]: 11913424 : if (spdk_unlikely(length > transport->opts.max_io_size)) {
2614 : 3 : SPDK_ERRLOG("SGL length 0x%x exceeds max io size 0x%x\n",
2615 : : length, transport->opts.max_io_size);
2616 : 3 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_LIMIT_EXCEEDED;
2617 : 3 : goto fatal_err;
2618 : : }
2619 : :
2620 : : /* fill request length and populate iovs */
2621 : 11913421 : req->length = length;
2622 : :
2623 [ - + - + ]: 11913421 : SPDK_DEBUGLOG(nvmf_tcp, "Data requested length= 0x%x\n", length);
2624 : :
2625 [ + + ]: 11913421 : if (spdk_unlikely(req->dif_enabled)) {
2626 : 493856 : req->dif.orig_length = length;
2627 : 493856 : length = spdk_dif_get_length_with_md(length, &req->dif.dif_ctx);
2628 : 493856 : req->dif.elba_length = length;
2629 : : }
2630 : :
2631 [ + + ]: 11913421 : if (nvmf_ctrlr_use_zcopy(req)) {
2632 [ - + - + ]: 905663 : SPDK_DEBUGLOG(nvmf_tcp, "Using zero-copy to execute request %p\n", tcp_req);
2633 : 905663 : req->data_from_pool = false;
2634 : 905663 : return 0;
2635 : : }
2636 : :
2637 [ + + ]: 11007758 : if (spdk_nvmf_request_get_buffers(req, group, transport, length)) {
2638 : : /* No available buffers. Queue this request up. */
2639 [ - + - + ]: 6 : SPDK_DEBUGLOG(nvmf_tcp, "No available large data buffers. Queueing request %p\n",
2640 : : tcp_req);
2641 : 6 : return 0;
2642 : : }
2643 : :
2644 [ - + - + ]: 11007752 : SPDK_DEBUGLOG(nvmf_tcp, "Request %p took %d buffer/s from central pool, and data=%p\n",
2645 : : tcp_req, req->iovcnt, req->iov[0].iov_base);
2646 : :
2647 : 11007752 : return 0;
2648 [ + - ]: 8116429 : } else if (sgl->generic.type == SPDK_NVME_SGL_TYPE_DATA_BLOCK &&
2649 [ + - ]: 8116429 : sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_OFFSET) {
2650 : 8116429 : uint64_t offset = sgl->address;
2651 : 8116429 : uint32_t max_len = transport->opts.in_capsule_data_size;
2652 : :
2653 [ - + - + ]: 8116429 : assert(tcp_req->has_in_capsule_data);
2654 : : /* Capsule Cmd with In-capsule Data should get data length from pdu header */
2655 : 8116429 : tqpair = tcp_req->pdu->qpair;
2656 : : /* receiving pdu is not same with the pdu in tcp_req */
2657 : 8116429 : pdu = tqpair->pdu_in_progress;
2658 : 8116429 : length = pdu->hdr.common.plen - pdu->psh_len - sizeof(struct spdk_nvme_tcp_common_pdu_hdr);
2659 [ - + + + ]: 8116429 : if (tqpair->host_ddgst_enable) {
2660 : 671713 : length -= SPDK_NVME_TCP_DIGEST_LEN;
2661 : : }
2662 : : /* This error is not defined in NVMe/TCP spec, take this error as fatal error */
2663 [ - + ]: 8116429 : if (spdk_unlikely(length != sgl->unkeyed.length)) {
2664 : 0 : SPDK_ERRLOG("In-Capsule Data length 0x%x is not equal to SGL data length 0x%x\n",
2665 : : length, sgl->unkeyed.length);
2666 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
2667 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_common_pdu_hdr, plen);
2668 : 0 : goto fatal_err;
2669 : : }
2670 : :
2671 [ - + - + ]: 8116429 : SPDK_DEBUGLOG(nvmf_tcp, "In-capsule data: offset 0x%" PRIx64 ", length 0x%x\n",
2672 : : offset, length);
2673 : :
2674 : : /* The NVMe/TCP transport does not use ICDOFF to control the in-capsule data offset. ICDOFF should be '0' */
2675 [ - + ]: 8116429 : if (spdk_unlikely(offset != 0)) {
2676 : : /* Not defined fatal error in NVMe/TCP spec, handle this error as a fatal error */
2677 : 0 : SPDK_ERRLOG("In-capsule offset 0x%" PRIx64 " should be ZERO in NVMe/TCP\n", offset);
2678 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER;
2679 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_cmd, ccsqe.dptr.sgl1.address);
2680 : 0 : goto fatal_err;
2681 : : }
2682 : :
2683 [ + + ]: 8116429 : if (spdk_unlikely(length > max_len)) {
2684 : : /* According to the SPEC we should support ICD up to 8192 bytes for admin and fabric commands */
2685 [ + - ]: 765 : if (length <= SPDK_NVME_TCP_IN_CAPSULE_DATA_MAX_SIZE &&
2686 [ - + - - ]: 765 : (cmd->opc == SPDK_NVME_OPC_FABRIC || req->qpair->qid == 0)) {
2687 : :
2688 : : /* Get a buffer from dedicated list */
2689 [ - + - + ]: 765 : SPDK_DEBUGLOG(nvmf_tcp, "Getting a buffer from control msg list\n");
2690 : 765 : tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group);
2691 [ - + ]: 765 : assert(tgroup->control_msg_list);
2692 : 765 : req->iov[0].iov_base = nvmf_tcp_control_msg_get(tgroup->control_msg_list);
2693 [ - + ]: 765 : if (!req->iov[0].iov_base) {
2694 : : /* No available buffers. Queue this request up. */
2695 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "No available ICD buffers. Queueing request %p\n", tcp_req);
2696 : 0 : return 0;
2697 : : }
2698 : : } else {
2699 : 0 : SPDK_ERRLOG("In-capsule data length 0x%x exceeds capsule length 0x%x\n",
2700 : : length, max_len);
2701 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_DATA_TRANSFER_LIMIT_EXCEEDED;
2702 : 0 : goto fatal_err;
2703 : : }
2704 : : } else {
2705 : 8115664 : req->iov[0].iov_base = tcp_req->buf;
2706 : : }
2707 : :
2708 : 8116429 : req->length = length;
2709 : 8116429 : req->data_from_pool = false;
2710 : :
2711 [ - + ]: 8116429 : if (spdk_unlikely(req->dif_enabled)) {
2712 : 0 : length = spdk_dif_get_length_with_md(length, &req->dif.dif_ctx);
2713 : 0 : req->dif.elba_length = length;
2714 : : }
2715 : :
2716 : 8116429 : req->iov[0].iov_len = length;
2717 : 8116429 : req->iovcnt = 1;
2718 : :
2719 : 8116429 : return 0;
2720 : : }
2721 : : /* If we want to handle the problem here, then we can't skip the following data segment.
2722 : : * Because this function runs before reading data part, now handle all errors as fatal errors. */
2723 : 0 : SPDK_ERRLOG("Invalid NVMf I/O Command SGL: Type 0x%x, Subtype 0x%x\n",
2724 : : sgl->generic.type, sgl->generic.subtype);
2725 : 0 : fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER;
2726 : 0 : error_offset = offsetof(struct spdk_nvme_tcp_cmd, ccsqe.dptr.sgl1.generic);
2727 : 3 : fatal_err:
2728 : 3 : nvmf_tcp_send_c2h_term_req(tcp_req->pdu->qpair, tcp_req->pdu, fes, error_offset);
2729 : 3 : return -1;
2730 : : }
2731 : :
2732 : : static inline enum spdk_nvme_media_error_status_code
2733 : 0 : nvmf_tcp_dif_error_to_compl_status(uint8_t err_type) {
2734 : : enum spdk_nvme_media_error_status_code result;
2735 : :
2736 [ # # # # ]: 0 : switch (err_type)
2737 : : {
2738 : 0 : case SPDK_DIF_REFTAG_ERROR:
2739 : 0 : result = SPDK_NVME_SC_REFERENCE_TAG_CHECK_ERROR;
2740 : 0 : break;
2741 : 0 : case SPDK_DIF_APPTAG_ERROR:
2742 : 0 : result = SPDK_NVME_SC_APPLICATION_TAG_CHECK_ERROR;
2743 : 0 : break;
2744 : 0 : case SPDK_DIF_GUARD_ERROR:
2745 : 0 : result = SPDK_NVME_SC_GUARD_CHECK_ERROR;
2746 : 0 : break;
2747 : 0 : default:
2748 : 0 : SPDK_UNREACHABLE();
2749 : : break;
2750 : : }
2751 : :
2752 : 0 : return result;
2753 : : }
2754 : :
2755 : : static void
2756 : 11113803 : _nvmf_tcp_send_c2h_data(struct spdk_nvmf_tcp_qpair *tqpair,
2757 : : struct spdk_nvmf_tcp_req *tcp_req)
2758 : : {
2759 : 11113803 : struct spdk_nvmf_tcp_transport *ttransport = SPDK_CONTAINEROF(
2760 : : tqpair->qpair.transport, struct spdk_nvmf_tcp_transport, transport);
2761 : : struct nvme_tcp_pdu *rsp_pdu;
2762 : : struct spdk_nvme_tcp_c2h_data_hdr *c2h_data;
2763 : : uint32_t plen, pdo, alignment;
2764 : : int rc;
2765 : :
2766 [ - + - + ]: 11113803 : SPDK_DEBUGLOG(nvmf_tcp, "enter\n");
2767 : :
2768 : 11113803 : rsp_pdu = tcp_req->pdu;
2769 [ - + ]: 11113803 : assert(rsp_pdu != NULL);
2770 : :
2771 : 11113803 : c2h_data = &rsp_pdu->hdr.c2h_data;
2772 : 11113803 : c2h_data->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_C2H_DATA;
2773 : 11113803 : plen = c2h_data->common.hlen = sizeof(*c2h_data);
2774 : :
2775 [ - + + + ]: 11113803 : if (tqpair->host_hdgst_enable) {
2776 : 576095 : plen += SPDK_NVME_TCP_DIGEST_LEN;
2777 : 576095 : c2h_data->common.flags |= SPDK_NVME_TCP_CH_FLAGS_HDGSTF;
2778 : : }
2779 : :
2780 : : /* set the psh */
2781 : 11113803 : c2h_data->cccid = tcp_req->req.cmd->nvme_cmd.cid;
2782 : 11113803 : c2h_data->datal = tcp_req->req.length - tcp_req->pdu->rw_offset;
2783 : 11113803 : c2h_data->datao = tcp_req->pdu->rw_offset;
2784 : :
2785 : : /* set the padding */
2786 : 11113803 : rsp_pdu->padding_len = 0;
2787 : 11113803 : pdo = plen;
2788 [ - + ]: 11113803 : if (tqpair->cpda) {
2789 [ # # ]: 0 : alignment = (tqpair->cpda + 1) << 2;
2790 [ # # # # ]: 0 : if (plen % alignment != 0) {
2791 [ # # ]: 0 : pdo = (plen + alignment) / alignment * alignment;
2792 : 0 : rsp_pdu->padding_len = pdo - plen;
2793 : 0 : plen = pdo;
2794 : : }
2795 : : }
2796 : :
2797 : 11113803 : c2h_data->common.pdo = pdo;
2798 : 11113803 : plen += c2h_data->datal;
2799 [ - + + + ]: 11113803 : if (tqpair->host_ddgst_enable) {
2800 : 1130945 : c2h_data->common.flags |= SPDK_NVME_TCP_CH_FLAGS_DDGSTF;
2801 : 1130945 : plen += SPDK_NVME_TCP_DIGEST_LEN;
2802 : : }
2803 : :
2804 : 11113803 : c2h_data->common.plen = plen;
2805 : :
2806 [ + + ]: 11113803 : if (spdk_unlikely(tcp_req->req.dif_enabled)) {
2807 : 711684 : rsp_pdu->dif_ctx = &tcp_req->req.dif.dif_ctx;
2808 : : }
2809 : :
2810 : 11113803 : nvme_tcp_pdu_set_data_buf(rsp_pdu, tcp_req->req.iov, tcp_req->req.iovcnt,
2811 : : c2h_data->datao, c2h_data->datal);
2812 : :
2813 : :
2814 : 11113803 : c2h_data->common.flags |= SPDK_NVME_TCP_C2H_DATA_FLAGS_LAST_PDU;
2815 : : /* Need to send the capsule response if response is not all 0 */
2816 [ + + + + ]: 11113803 : if (ttransport->tcp_opts.c2h_success &&
2817 [ + + + - ]: 157392 : tcp_req->rsp.cdw0 == 0 && tcp_req->rsp.cdw1 == 0) {
2818 : 157389 : c2h_data->common.flags |= SPDK_NVME_TCP_C2H_DATA_FLAGS_SUCCESS;
2819 : : }
2820 : :
2821 [ + + ]: 11113803 : if (spdk_unlikely(tcp_req->req.dif_enabled)) {
2822 : 711684 : struct spdk_nvme_cpl *rsp = &tcp_req->req.rsp->nvme_cpl;
2823 : 711684 : struct spdk_dif_error err_blk = {};
2824 : 711684 : uint32_t mapped_length = 0;
2825 : 711684 : uint32_t available_iovs = SPDK_COUNTOF(rsp_pdu->iov);
2826 : 711684 : uint32_t ddgst_len = 0;
2827 : :
2828 [ - + + + ]: 711684 : if (tqpair->host_ddgst_enable) {
2829 : : /* Data digest consumes additional iov entry */
2830 : 163392 : available_iovs--;
2831 : : /* plen needs to be updated since nvme_tcp_build_iovs compares expected and actual plen */
2832 : 163392 : ddgst_len = SPDK_NVME_TCP_DIGEST_LEN;
2833 : 163392 : c2h_data->common.plen -= ddgst_len;
2834 : : }
2835 : : /* Temp call to estimate if data can be described by limited number of iovs.
2836 : : * iov vector will be rebuilt in nvmf_tcp_qpair_write_pdu */
2837 [ - + ]: 711684 : nvme_tcp_build_iovs(rsp_pdu->iov, available_iovs, rsp_pdu, tqpair->host_hdgst_enable,
2838 : : false, &mapped_length);
2839 : :
2840 [ + + ]: 711684 : if (mapped_length != c2h_data->common.plen) {
2841 : 217828 : c2h_data->datal = mapped_length - (c2h_data->common.plen - c2h_data->datal);
2842 [ - + - + ]: 217828 : SPDK_DEBUGLOG(nvmf_tcp,
2843 : : "Part C2H, data_len %u (of %u), PDU len %u, updated PDU len %u, offset %u\n",
2844 : : c2h_data->datal, tcp_req->req.length, c2h_data->common.plen, mapped_length, rsp_pdu->rw_offset);
2845 : 217828 : c2h_data->common.plen = mapped_length;
2846 : :
2847 : : /* Rebuild pdu->data_iov since data length is changed */
2848 : 217828 : nvme_tcp_pdu_set_data_buf(rsp_pdu, tcp_req->req.iov, tcp_req->req.iovcnt, c2h_data->datao,
2849 : : c2h_data->datal);
2850 : :
2851 : 217828 : c2h_data->common.flags &= ~(SPDK_NVME_TCP_C2H_DATA_FLAGS_LAST_PDU |
2852 : : SPDK_NVME_TCP_C2H_DATA_FLAGS_SUCCESS);
2853 : : }
2854 : :
2855 : 711684 : c2h_data->common.plen += ddgst_len;
2856 : :
2857 [ - + ]: 711684 : assert(rsp_pdu->rw_offset <= tcp_req->req.length);
2858 : :
2859 : 711684 : rc = spdk_dif_verify_stream(rsp_pdu->data_iov, rsp_pdu->data_iovcnt,
2860 : : 0, rsp_pdu->data_len, rsp_pdu->dif_ctx, &err_blk);
2861 [ - + ]: 711684 : if (rc != 0) {
2862 : 0 : SPDK_ERRLOG("DIF error detected. type=%d, offset=%" PRIu32 "\n",
2863 : : err_blk.err_type, err_blk.err_offset);
2864 : 0 : rsp->status.sct = SPDK_NVME_SCT_MEDIA_ERROR;
2865 : 0 : rsp->status.sc = nvmf_tcp_dif_error_to_compl_status(err_blk.err_type);
2866 : 0 : nvmf_tcp_send_capsule_resp_pdu(tcp_req, tqpair);
2867 : 0 : return;
2868 : : }
2869 : : }
2870 : :
2871 : 11113803 : rsp_pdu->rw_offset += c2h_data->datal;
2872 : 11113803 : nvmf_tcp_qpair_write_req_pdu(tqpair, tcp_req, nvmf_tcp_pdu_c2h_data_complete, tcp_req);
2873 : : }
2874 : :
2875 : : static void
2876 : 10895975 : nvmf_tcp_send_c2h_data(struct spdk_nvmf_tcp_qpair *tqpair,
2877 : : struct spdk_nvmf_tcp_req *tcp_req)
2878 : : {
2879 : 10895975 : nvmf_tcp_req_pdu_init(tcp_req);
2880 : 10895975 : _nvmf_tcp_send_c2h_data(tqpair, tcp_req);
2881 : 10895975 : }
2882 : :
2883 : : static int
2884 : 20223119 : request_transfer_out(struct spdk_nvmf_request *req)
2885 : : {
2886 : : struct spdk_nvmf_tcp_req *tcp_req;
2887 : : struct spdk_nvmf_qpair *qpair;
2888 : : struct spdk_nvmf_tcp_qpair *tqpair;
2889 : : struct spdk_nvme_cpl *rsp;
2890 : :
2891 [ - + - + ]: 20223119 : SPDK_DEBUGLOG(nvmf_tcp, "enter\n");
2892 : :
2893 : 20223119 : qpair = req->qpair;
2894 : 20223119 : rsp = &req->rsp->nvme_cpl;
2895 : 20223119 : tcp_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_tcp_req, req);
2896 : :
2897 : : /* Advance our sq_head pointer */
2898 [ + + ]: 20223119 : if (qpair->sq_head == qpair->sq_head_max) {
2899 : 158430 : qpair->sq_head = 0;
2900 : : } else {
2901 : 20064689 : qpair->sq_head++;
2902 : : }
2903 : 20223119 : rsp->sqhd = qpair->sq_head;
2904 : :
2905 : 20223119 : tqpair = SPDK_CONTAINEROF(tcp_req->req.qpair, struct spdk_nvmf_tcp_qpair, qpair);
2906 : 20223119 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST);
2907 [ + + + + ]: 20223119 : if (rsp->status.sc == SPDK_NVME_SC_SUCCESS && req->xfer == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
2908 : 10895963 : nvmf_tcp_send_c2h_data(tqpair, tcp_req);
2909 : : } else {
2910 : 9327156 : nvmf_tcp_send_capsule_resp_pdu(tcp_req, tqpair);
2911 : : }
2912 : :
2913 : 20223119 : return 0;
2914 : : }
2915 : :
2916 : : static void
2917 : 20231761 : nvmf_tcp_check_fused_ordering(struct spdk_nvmf_tcp_transport *ttransport,
2918 : : struct spdk_nvmf_tcp_qpair *tqpair,
2919 : : struct spdk_nvmf_tcp_req *tcp_req)
2920 : : {
2921 : : enum spdk_nvme_cmd_fuse last, next;
2922 : :
2923 [ + + ]: 20231761 : last = tqpair->fused_first ? tqpair->fused_first->cmd.fuse : SPDK_NVME_CMD_FUSE_NONE;
2924 : 20231761 : next = tcp_req->cmd.fuse;
2925 : :
2926 [ - + ]: 20231761 : assert(last != SPDK_NVME_CMD_FUSE_SECOND);
2927 : :
2928 [ + + + + ]: 20231761 : if (spdk_likely(last == SPDK_NVME_CMD_FUSE_NONE && next == SPDK_NVME_CMD_FUSE_NONE)) {
2929 : 20223469 : return;
2930 : : }
2931 : :
2932 [ + + ]: 8292 : if (last == SPDK_NVME_CMD_FUSE_FIRST) {
2933 [ + - ]: 4146 : if (next == SPDK_NVME_CMD_FUSE_SECOND) {
2934 : : /* This is a valid pair of fused commands. Point them at each other
2935 : : * so they can be submitted consecutively once ready to be executed.
2936 : : */
2937 : 4146 : tqpair->fused_first->fused_pair = tcp_req;
2938 : 4146 : tcp_req->fused_pair = tqpair->fused_first;
2939 : 4146 : tqpair->fused_first = NULL;
2940 : 4146 : return;
2941 : : } else {
2942 : : /* Mark the last req as failed since it wasn't followed by a SECOND. */
2943 : 0 : tqpair->fused_first->fused_failed = true;
2944 : :
2945 : : /*
2946 : : * If the last req is in READY_TO_EXECUTE state, then call
2947 : : * nvmf_tcp_req_process(), otherwise nothing else will kick it.
2948 : : */
2949 [ # # ]: 0 : if (tqpair->fused_first->state == TCP_REQUEST_STATE_READY_TO_EXECUTE) {
2950 : 0 : nvmf_tcp_req_process(ttransport, tqpair->fused_first);
2951 : : }
2952 : :
2953 : 0 : tqpair->fused_first = NULL;
2954 : : }
2955 : : }
2956 : :
2957 [ + - ]: 4146 : if (next == SPDK_NVME_CMD_FUSE_FIRST) {
2958 : : /* Set tqpair->fused_first here so that we know to check that the next request
2959 : : * is a SECOND (and to fail this one if it isn't).
2960 : : */
2961 : 4146 : tqpair->fused_first = tcp_req;
2962 [ # # ]: 0 : } else if (next == SPDK_NVME_CMD_FUSE_SECOND) {
2963 : : /* Mark this req failed since it is a SECOND and the last one was not a FIRST. */
2964 : 0 : tcp_req->fused_failed = true;
2965 : : }
2966 : : }
2967 : :
2968 : : static bool
2969 : 71325144 : nvmf_tcp_req_process(struct spdk_nvmf_tcp_transport *ttransport,
2970 : : struct spdk_nvmf_tcp_req *tcp_req)
2971 : : {
2972 : : struct spdk_nvmf_tcp_qpair *tqpair;
2973 : : uint32_t plen;
2974 : : struct nvme_tcp_pdu *pdu;
2975 : : enum spdk_nvmf_tcp_req_state prev_state;
2976 : 71325144 : bool progress = false;
2977 : 71325144 : struct spdk_nvmf_transport *transport = &ttransport->transport;
2978 : : struct spdk_nvmf_transport_poll_group *group;
2979 : : struct spdk_nvmf_tcp_poll_group *tgroup;
2980 : :
2981 : 71325144 : tqpair = SPDK_CONTAINEROF(tcp_req->req.qpair, struct spdk_nvmf_tcp_qpair, qpair);
2982 : 71325144 : group = &tqpair->group->group;
2983 [ - + ]: 71325144 : assert(tcp_req->state != TCP_REQUEST_STATE_FREE);
2984 : :
2985 : : /* If the qpair is not active, we need to abort the outstanding requests. */
2986 [ + + ]: 71325144 : if (!spdk_nvmf_qpair_is_active(&tqpair->qpair)) {
2987 [ - + ]: 886383 : if (tcp_req->state == TCP_REQUEST_STATE_NEED_BUFFER) {
2988 : 0 : nvmf_tcp_request_get_buffers_abort(tcp_req);
2989 : : }
2990 : 886383 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_COMPLETED);
2991 : : }
2992 : :
2993 : : /* The loop here is to allow for several back-to-back state changes. */
2994 : : do {
2995 : 194217190 : prev_state = tcp_req->state;
2996 : :
2997 [ - + - + ]: 194217190 : SPDK_DEBUGLOG(nvmf_tcp, "Request %p entering state %d on tqpair=%p\n", tcp_req, prev_state,
2998 : : tqpair);
2999 : :
3000 [ + + + + : 194217190 : switch (tcp_req->state) {
+ + + + +
+ + + + +
+ - ]
3001 : 21106432 : case TCP_REQUEST_STATE_FREE:
3002 : : /* Some external code must kick a request into TCP_REQUEST_STATE_NEW
3003 : : * to escape this state. */
3004 : 21106432 : break;
3005 : 20231761 : case TCP_REQUEST_STATE_NEW:
3006 [ + + + + ]: 20231761 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_NEW, tqpair->qpair.trace_id, 0, (uintptr_t)tcp_req,
3007 : : tqpair->qpair.queue_depth);
3008 : :
3009 : : /* copy the cmd from the receive pdu */
3010 : 20231761 : tcp_req->cmd = tqpair->pdu_in_progress->hdr.capsule_cmd.ccsqe;
3011 : :
3012 [ + + ]: 20231761 : if (spdk_unlikely(spdk_nvmf_request_get_dif_ctx(&tcp_req->req, &tcp_req->req.dif.dif_ctx))) {
3013 : 493856 : tcp_req->req.dif_enabled = true;
3014 : 493856 : tqpair->pdu_in_progress->dif_ctx = &tcp_req->req.dif.dif_ctx;
3015 : : }
3016 : :
3017 : 20231761 : nvmf_tcp_check_fused_ordering(ttransport, tqpair, tcp_req);
3018 : :
3019 : : /* The next state transition depends on the data transfer needs of this request. */
3020 : 20231761 : tcp_req->req.xfer = spdk_nvmf_req_get_xfer(&tcp_req->req);
3021 : :
3022 [ + + ]: 20231761 : if (spdk_unlikely(tcp_req->req.xfer == SPDK_NVME_DATA_BIDIRECTIONAL)) {
3023 : 3 : nvmf_tcp_req_set_cpl(tcp_req, SPDK_NVME_SCT_GENERIC, SPDK_NVME_SC_INVALID_OPCODE);
3024 : 3 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
3025 : 3 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_COMPLETE);
3026 [ - + - + ]: 3 : SPDK_DEBUGLOG(nvmf_tcp, "Request %p: invalid xfer type (BIDIRECTIONAL)\n", tcp_req);
3027 : 3 : break;
3028 : : }
3029 : :
3030 : : /* If no data to transfer, ready to execute. */
3031 [ + + ]: 20231758 : if (tcp_req->req.xfer == SPDK_NVME_DATA_NONE) {
3032 : : /* Reset the tqpair receiving pdu state */
3033 : 201908 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
3034 : 201908 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_EXECUTE);
3035 : 201908 : break;
3036 : : }
3037 : :
3038 : 20029850 : pdu = tqpair->pdu_in_progress;
3039 : 20029850 : plen = pdu->hdr.common.hlen;
3040 [ - + + + ]: 20029850 : if (tqpair->host_hdgst_enable) {
3041 : 660938 : plen += SPDK_NVME_TCP_DIGEST_LEN;
3042 : : }
3043 [ + + ]: 20029850 : if (pdu->hdr.common.plen != plen) {
3044 : 8116438 : tcp_req->has_in_capsule_data = true;
3045 : : } else {
3046 : : /* Data is transmitted by C2H PDUs */
3047 : 11913412 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
3048 : : }
3049 : :
3050 : 20029850 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_NEED_BUFFER);
3051 : 20029850 : break;
3052 : 20029853 : case TCP_REQUEST_STATE_NEED_BUFFER:
3053 [ + + + + ]: 20029853 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_NEED_BUFFER, tqpair->qpair.trace_id, 0,
3054 : : (uintptr_t)tcp_req);
3055 : :
3056 [ - + ]: 20029853 : assert(tcp_req->req.xfer != SPDK_NVME_DATA_NONE);
3057 : :
3058 : : /* Try to get a data buffer */
3059 [ + + ]: 20029853 : if (nvmf_tcp_req_parse_sgl(tcp_req, transport, group) < 0) {
3060 : 3 : break;
3061 : : }
3062 : :
3063 : : /* Get a zcopy buffer if the request can be serviced through zcopy */
3064 [ + + ]: 20029850 : if (spdk_nvmf_request_using_zcopy(&tcp_req->req)) {
3065 [ - + ]: 905663 : if (spdk_unlikely(tcp_req->req.dif_enabled)) {
3066 [ # # ]: 0 : assert(tcp_req->req.dif.elba_length >= tcp_req->req.length);
3067 : 0 : tcp_req->req.length = tcp_req->req.dif.elba_length;
3068 : : }
3069 : :
3070 : 905663 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_AWAITING_ZCOPY_START);
3071 : 905663 : spdk_nvmf_request_zcopy_start(&tcp_req->req);
3072 : 905663 : break;
3073 : : }
3074 : :
3075 [ + + ]: 19124187 : if (tcp_req->req.iovcnt < 1) {
3076 [ - + - + ]: 3 : SPDK_DEBUGLOG(nvmf_tcp, "No buffer allocated for tcp_req(%p) on tqpair(%p\n)",
3077 : : tcp_req, tqpair);
3078 : : /* No buffers available. */
3079 : 3 : break;
3080 : : }
3081 : :
3082 : : /* If data is transferring from host to controller, we need to do a transfer from the host. */
3083 [ + + ]: 19124184 : if (tcp_req->req.xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER) {
3084 [ + + ]: 8433028 : if (tcp_req->req.data_from_pool) {
3085 [ - + - + ]: 316593 : SPDK_DEBUGLOG(nvmf_tcp, "Sending R2T for tcp_req(%p) on tqpair=%p\n", tcp_req, tqpair);
3086 : 316593 : nvmf_tcp_send_r2t_pdu(tqpair, tcp_req);
3087 : : } else {
3088 : : struct nvme_tcp_pdu *pdu;
3089 : :
3090 : 8116435 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER);
3091 : :
3092 : 8116435 : pdu = tqpair->pdu_in_progress;
3093 [ - + - + ]: 8116435 : SPDK_DEBUGLOG(nvmf_tcp, "Not need to send r2t for tcp_req(%p) on tqpair=%p\n", tcp_req,
3094 : : tqpair);
3095 : : /* No need to send r2t, contained in the capsuled data */
3096 : 8116435 : nvme_tcp_pdu_set_data_buf(pdu, tcp_req->req.iov, tcp_req->req.iovcnt,
3097 : : 0, tcp_req->req.length);
3098 : 8116435 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
3099 : : }
3100 : 8433028 : break;
3101 : : }
3102 : :
3103 : 10691156 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_EXECUTE);
3104 : 10691156 : break;
3105 : 905663 : case TCP_REQUEST_STATE_AWAITING_ZCOPY_START:
3106 [ + - + - ]: 905663 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_AWAIT_ZCOPY_START, tqpair->qpair.trace_id, 0,
3107 : : (uintptr_t)tcp_req);
3108 : : /* Some external code must kick a request into TCP_REQUEST_STATE_ZCOPY_START_COMPLETED
3109 : : * to escape this state. */
3110 : 905663 : break;
3111 : 905663 : case TCP_REQUEST_STATE_ZCOPY_START_COMPLETED:
3112 [ + - + - ]: 905663 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_ZCOPY_START_COMPLETED, tqpair->qpair.trace_id, 0,
3113 : : (uintptr_t)tcp_req);
3114 [ + + - + ]: 905663 : if (spdk_unlikely(spdk_nvme_cpl_is_error(&tcp_req->req.rsp->nvme_cpl))) {
3115 [ - + - + ]: 25095 : SPDK_DEBUGLOG(nvmf_tcp, "Zero-copy start failed for tcp_req(%p) on tqpair=%p\n",
3116 : : tcp_req, tqpair);
3117 : 25095 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_COMPLETE);
3118 : 25095 : break;
3119 : : }
3120 [ + + ]: 880568 : if (tcp_req->req.xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER) {
3121 [ - + - + ]: 452975 : SPDK_DEBUGLOG(nvmf_tcp, "Sending R2T for tcp_req(%p) on tqpair=%p\n", tcp_req, tqpair);
3122 : 452975 : nvmf_tcp_send_r2t_pdu(tqpair, tcp_req);
3123 : : } else {
3124 : 427593 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_EXECUTED);
3125 : : }
3126 : 880568 : break;
3127 : 769568 : case TCP_REQUEST_STATE_AWAITING_R2T_ACK:
3128 [ + - + + ]: 769568 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_AWAIT_R2T_ACK, tqpair->qpair.trace_id, 0,
3129 : : (uintptr_t)tcp_req);
3130 : : /* The R2T completion or the h2c data incoming will kick it out of this state. */
3131 : 769568 : break;
3132 : 8116435 : case TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER:
3133 : :
3134 [ + + + + ]: 8116435 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER, tqpair->qpair.trace_id,
3135 : : 0, (uintptr_t)tcp_req);
3136 : : /* Some external code must kick a request into TCP_REQUEST_STATE_READY_TO_EXECUTE
3137 : : * to escape this state. */
3138 : 8116435 : break;
3139 : 19776332 : case TCP_REQUEST_STATE_READY_TO_EXECUTE:
3140 [ + + + + ]: 19776332 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_READY_TO_EXECUTE, tqpair->qpair.trace_id, 0,
3141 : : (uintptr_t)tcp_req);
3142 : :
3143 [ + + ]: 19776332 : if (spdk_unlikely(tcp_req->req.dif_enabled)) {
3144 [ - + ]: 493856 : assert(tcp_req->req.dif.elba_length >= tcp_req->req.length);
3145 : 493856 : tcp_req->req.length = tcp_req->req.dif.elba_length;
3146 : : }
3147 : :
3148 [ + + ]: 19776332 : if (tcp_req->cmd.fuse != SPDK_NVME_CMD_FUSE_NONE) {
3149 [ - + - + ]: 8292 : if (tcp_req->fused_failed) {
3150 : : /* This request failed FUSED semantics. Fail it immediately, without
3151 : : * even sending it to the target layer.
3152 : : */
3153 : 0 : nvmf_tcp_req_set_cpl(tcp_req, SPDK_NVME_SCT_GENERIC, SPDK_NVME_SC_ABORTED_MISSING_FUSED);
3154 : 0 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_COMPLETE);
3155 : 0 : break;
3156 : : }
3157 : :
3158 [ + + ]: 8292 : if (tcp_req->fused_pair == NULL ||
3159 [ + - ]: 4146 : tcp_req->fused_pair->state != TCP_REQUEST_STATE_READY_TO_EXECUTE) {
3160 : : /* This request is ready to execute, but either we don't know yet if it's
3161 : : * valid - i.e. this is a FIRST but we haven't received the next request yet),
3162 : : * or the other request of this fused pair isn't ready to execute. So
3163 : : * break here and this request will get processed later either when the
3164 : : * other request is ready or we find that this request isn't valid.
3165 : : */
3166 : : break;
3167 : : }
3168 : : }
3169 : :
3170 [ + + ]: 19772186 : if (!spdk_nvmf_request_using_zcopy(&tcp_req->req)) {
3171 : 19319211 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_EXECUTING);
3172 : : /* If we get to this point, and this request is a fused command, we know that
3173 : : * it is part of a valid sequence (FIRST followed by a SECOND) and that both
3174 : : * requests are READY_TO_EXECUTE. So call spdk_nvmf_request_exec() both on this
3175 : : * request, and the other request of the fused pair, in the correct order.
3176 : : * Also clear the ->fused_pair pointers on both requests, since after this point
3177 : : * we no longer need to maintain the relationship between these two requests.
3178 : : */
3179 [ + + ]: 19319211 : if (tcp_req->cmd.fuse == SPDK_NVME_CMD_FUSE_SECOND) {
3180 [ - + ]: 4146 : assert(tcp_req->fused_pair != NULL);
3181 [ - + ]: 4146 : assert(tcp_req->fused_pair->fused_pair == tcp_req);
3182 : 4146 : nvmf_tcp_req_set_state(tcp_req->fused_pair, TCP_REQUEST_STATE_EXECUTING);
3183 : 4146 : spdk_nvmf_request_exec(&tcp_req->fused_pair->req);
3184 : 4146 : tcp_req->fused_pair->fused_pair = NULL;
3185 : 4146 : tcp_req->fused_pair = NULL;
3186 : : }
3187 : 19319211 : spdk_nvmf_request_exec(&tcp_req->req);
3188 [ - + ]: 19319211 : if (tcp_req->cmd.fuse == SPDK_NVME_CMD_FUSE_FIRST) {
3189 [ # # ]: 0 : assert(tcp_req->fused_pair != NULL);
3190 [ # # ]: 0 : assert(tcp_req->fused_pair->fused_pair == tcp_req);
3191 : 0 : nvmf_tcp_req_set_state(tcp_req->fused_pair, TCP_REQUEST_STATE_EXECUTING);
3192 : 0 : spdk_nvmf_request_exec(&tcp_req->fused_pair->req);
3193 : 0 : tcp_req->fused_pair->fused_pair = NULL;
3194 : 0 : tcp_req->fused_pair = NULL;
3195 : : }
3196 : : } else {
3197 : : /* For zero-copy, only requests with data coming from host to the
3198 : : * controller can end up here. */
3199 [ - + ]: 452975 : assert(tcp_req->req.xfer == SPDK_NVME_DATA_HOST_TO_CONTROLLER);
3200 : 452975 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_AWAITING_ZCOPY_COMMIT);
3201 : 452975 : spdk_nvmf_request_zcopy_end(&tcp_req->req, true);
3202 : : }
3203 : :
3204 : 19772186 : break;
3205 : 18996539 : case TCP_REQUEST_STATE_EXECUTING:
3206 [ + + + + ]: 18996539 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_EXECUTING, tqpair->qpair.trace_id, 0, (uintptr_t)tcp_req);
3207 : : /* Some external code must kick a request into TCP_REQUEST_STATE_EXECUTED
3208 : : * to escape this state. */
3209 : 18996539 : break;
3210 : 452975 : case TCP_REQUEST_STATE_AWAITING_ZCOPY_COMMIT:
3211 [ + - + - ]: 452975 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_AWAIT_ZCOPY_COMMIT, tqpair->qpair.trace_id, 0,
3212 : : (uintptr_t)tcp_req);
3213 : : /* Some external code must kick a request into TCP_REQUEST_STATE_EXECUTED
3214 : : * to escape this state. */
3215 : 452975 : break;
3216 : 20195449 : case TCP_REQUEST_STATE_EXECUTED:
3217 [ + + + + ]: 20195449 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_EXECUTED, tqpair->qpair.trace_id, 0, (uintptr_t)tcp_req);
3218 : :
3219 [ + + ]: 20195449 : if (spdk_unlikely(tcp_req->req.dif_enabled)) {
3220 : 493856 : tcp_req->req.length = tcp_req->req.dif.orig_length;
3221 : : }
3222 : :
3223 : 20195449 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_READY_TO_COMPLETE);
3224 : 20195449 : break;
3225 : 20223119 : case TCP_REQUEST_STATE_READY_TO_COMPLETE:
3226 [ + + + + ]: 20223119 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_READY_TO_COMPLETE, tqpair->qpair.trace_id, 0,
3227 : : (uintptr_t)tcp_req);
3228 [ - + ]: 20223119 : if (request_transfer_out(&tcp_req->req) != 0) {
3229 : 0 : assert(0); /* No good way to handle this currently */
3230 : : }
3231 : 20223119 : break;
3232 : 20545787 : case TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST:
3233 [ + + + + ]: 20545787 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_TRANSFERRING_CONTROLLER_TO_HOST, tqpair->qpair.trace_id,
3234 : : 0, (uintptr_t)tcp_req);
3235 : : /* Some external code must kick a request into TCP_REQUEST_STATE_COMPLETED
3236 : : * to escape this state. */
3237 : 20545787 : break;
3238 : 427593 : case TCP_REQUEST_STATE_AWAITING_ZCOPY_RELEASE:
3239 [ + - + - ]: 427593 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_AWAIT_ZCOPY_RELEASE, tqpair->qpair.trace_id, 0,
3240 : : (uintptr_t)tcp_req);
3241 : : /* Some external code must kick a request into TCP_REQUEST_STATE_COMPLETED
3242 : : * to escape this state. */
3243 : 427593 : break;
3244 : 21534021 : case TCP_REQUEST_STATE_COMPLETED:
3245 [ + + + + ]: 21534021 : spdk_trace_record(TRACE_TCP_REQUEST_STATE_COMPLETED, tqpair->qpair.trace_id, 0, (uintptr_t)tcp_req,
3246 : : tqpair->qpair.queue_depth);
3247 : : /* If there's an outstanding PDU sent to the host, the request is completed
3248 : : * due to the qpair being disconnected. We must delay the completion until
3249 : : * that write is done to avoid freeing the request twice. */
3250 [ - + - + ]: 21534021 : if (spdk_unlikely(tcp_req->pdu_in_use)) {
3251 [ # # # # ]: 0 : SPDK_DEBUGLOG(nvmf_tcp, "Delaying completion due to outstanding "
3252 : : "write on req=%p\n", tcp_req);
3253 : : /* This can only happen for zcopy requests */
3254 [ # # ]: 0 : assert(spdk_nvmf_request_using_zcopy(&tcp_req->req));
3255 [ # # ]: 0 : assert(!spdk_nvmf_qpair_is_active(&tqpair->qpair));
3256 : 0 : break;
3257 : : }
3258 : :
3259 [ + + ]: 21534021 : if (tcp_req->req.data_from_pool) {
3260 : 11007749 : spdk_nvmf_request_free_buffers(&tcp_req->req, group, transport);
3261 [ - + + + : 10526272 : } else if (spdk_unlikely(tcp_req->has_in_capsule_data &&
+ + - + +
+ + + +
+ ]
3262 : : (tcp_req->cmd.opc == SPDK_NVME_OPC_FABRIC ||
3263 : : tqpair->qpair.qid == 0) && tcp_req->req.length > transport->opts.in_capsule_data_size)) {
3264 : 765 : tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group);
3265 [ - + ]: 765 : assert(tgroup->control_msg_list);
3266 [ - + - + ]: 765 : SPDK_DEBUGLOG(nvmf_tcp, "Put buf to control msg list\n");
3267 : 765 : nvmf_tcp_control_msg_put(tgroup->control_msg_list,
3268 : : tcp_req->req.iov[0].iov_base);
3269 [ + + ]: 10525507 : } else if (tcp_req->req.zcopy_bdev_io != NULL) {
3270 : : /* If the request has an unreleased zcopy bdev_io, it's either a
3271 : : * read, a failed write, or the qpair is being disconnected */
3272 [ - + ]: 427593 : assert(spdk_nvmf_request_using_zcopy(&tcp_req->req));
3273 [ - + - - : 427593 : assert(tcp_req->req.xfer == SPDK_NVME_DATA_CONTROLLER_TO_HOST ||
- - - - ]
3274 : : spdk_nvme_cpl_is_error(&tcp_req->req.rsp->nvme_cpl) ||
3275 : : !spdk_nvmf_qpair_is_active(&tqpair->qpair));
3276 : 427593 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_AWAITING_ZCOPY_RELEASE);
3277 : 427593 : spdk_nvmf_request_zcopy_end(&tcp_req->req, false);
3278 : 427593 : break;
3279 : : }
3280 : 21106428 : tcp_req->req.length = 0;
3281 : 21106428 : tcp_req->req.iovcnt = 0;
3282 : 21106428 : tcp_req->fused_failed = false;
3283 [ - + ]: 21106428 : if (tcp_req->fused_pair) {
3284 : : /* This req was part of a valid fused pair, but failed before it got to
3285 : : * READ_TO_EXECUTE state. This means we need to fail the other request
3286 : : * in the pair, because it is no longer part of a valid pair. If the pair
3287 : : * already reached READY_TO_EXECUTE state, we need to kick it.
3288 : : */
3289 : 0 : tcp_req->fused_pair->fused_failed = true;
3290 [ # # ]: 0 : if (tcp_req->fused_pair->state == TCP_REQUEST_STATE_READY_TO_EXECUTE) {
3291 : 0 : nvmf_tcp_req_process(ttransport, tcp_req->fused_pair);
3292 : : }
3293 : 0 : tcp_req->fused_pair = NULL;
3294 : : }
3295 : :
3296 : 21106428 : nvmf_tcp_req_put(tqpair, tcp_req);
3297 : 21106428 : break;
3298 : 0 : case TCP_REQUEST_NUM_STATES:
3299 : : default:
3300 : 0 : assert(0);
3301 : : break;
3302 : : }
3303 : :
3304 [ + + ]: 194217190 : if (tcp_req->state != prev_state) {
3305 : 122892046 : progress = true;
3306 : : }
3307 [ + + ]: 194217190 : } while (tcp_req->state != prev_state);
3308 : :
3309 : 71325144 : return progress;
3310 : : }
3311 : :
3312 : : static void
3313 : 61674883 : nvmf_tcp_sock_cb(void *arg, struct spdk_sock_group *group, struct spdk_sock *sock)
3314 : : {
3315 : 61674883 : struct spdk_nvmf_tcp_qpair *tqpair = arg;
3316 : : int rc;
3317 : :
3318 [ - + ]: 61674883 : assert(tqpair != NULL);
3319 : 61674883 : rc = nvmf_tcp_sock_process(tqpair);
3320 : :
3321 : : /* If there was a new socket error, disconnect */
3322 [ + + ]: 61674883 : if (rc < 0) {
3323 : 302094 : nvmf_tcp_qpair_disconnect(tqpair);
3324 : : }
3325 : 61674883 : }
3326 : :
3327 : : static int
3328 : 12324 : nvmf_tcp_poll_group_add(struct spdk_nvmf_transport_poll_group *group,
3329 : : struct spdk_nvmf_qpair *qpair)
3330 : : {
3331 : : struct spdk_nvmf_tcp_poll_group *tgroup;
3332 : : struct spdk_nvmf_tcp_qpair *tqpair;
3333 : : int rc;
3334 : :
3335 : 12324 : tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group);
3336 : 12324 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
3337 : :
3338 : 12324 : rc = nvmf_tcp_qpair_sock_init(tqpair);
3339 [ - + ]: 12324 : if (rc != 0) {
3340 : 0 : SPDK_ERRLOG("Cannot set sock opt for tqpair=%p\n", tqpair);
3341 : 0 : return -1;
3342 : : }
3343 : :
3344 : 12324 : rc = nvmf_tcp_qpair_init(&tqpair->qpair);
3345 [ - + ]: 12324 : if (rc < 0) {
3346 : 0 : SPDK_ERRLOG("Cannot init tqpair=%p\n", tqpair);
3347 : 0 : return -1;
3348 : : }
3349 : :
3350 : 12324 : rc = nvmf_tcp_qpair_init_mem_resource(tqpair);
3351 [ - + ]: 12324 : if (rc < 0) {
3352 : 0 : SPDK_ERRLOG("Cannot init memory resource info for tqpair=%p\n", tqpair);
3353 : 0 : return -1;
3354 : : }
3355 : :
3356 : 12324 : rc = spdk_sock_group_add_sock(tgroup->sock_group, tqpair->sock,
3357 : : nvmf_tcp_sock_cb, tqpair);
3358 [ - + ]: 12324 : if (rc != 0) {
3359 : 0 : SPDK_ERRLOG("Could not add sock to sock_group: %s (%d)\n",
3360 : : spdk_strerror(errno), errno);
3361 : 0 : return -1;
3362 : : }
3363 : :
3364 : 12324 : tqpair->group = tgroup;
3365 : 12324 : nvmf_tcp_qpair_set_state(tqpair, NVME_TCP_QPAIR_STATE_INVALID);
3366 : 12324 : TAILQ_INSERT_TAIL(&tgroup->qpairs, tqpair, link);
3367 : :
3368 : 12324 : return 0;
3369 : : }
3370 : :
3371 : : static int
3372 : 12324 : nvmf_tcp_poll_group_remove(struct spdk_nvmf_transport_poll_group *group,
3373 : : struct spdk_nvmf_qpair *qpair)
3374 : : {
3375 : : struct spdk_nvmf_tcp_poll_group *tgroup;
3376 : : struct spdk_nvmf_tcp_qpair *tqpair;
3377 : : int rc;
3378 : :
3379 : 12324 : tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group);
3380 : 12324 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
3381 : :
3382 [ - + ]: 12324 : assert(tqpair->group == tgroup);
3383 : :
3384 [ - + - + ]: 12324 : SPDK_DEBUGLOG(nvmf_tcp, "remove tqpair=%p from the tgroup=%p\n", tqpair, tgroup);
3385 [ + + ]: 12324 : if (tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_REQ) {
3386 : : /* Change the state to move the qpair from the await_req list to the main list
3387 : : * and prevent adding it again later by nvmf_tcp_qpair_set_recv_state() */
3388 : 32 : nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_QUIESCING);
3389 : : }
3390 [ + + ]: 12324 : TAILQ_REMOVE(&tgroup->qpairs, tqpair, link);
3391 : :
3392 : : /* Try to force out any pending writes */
3393 : 12324 : spdk_sock_flush(tqpair->sock);
3394 : :
3395 : 12324 : rc = spdk_sock_group_remove_sock(tgroup->sock_group, tqpair->sock);
3396 [ - + ]: 12324 : if (rc != 0) {
3397 : 0 : SPDK_ERRLOG("Could not remove sock from sock_group: %s (%d)\n",
3398 : : spdk_strerror(errno), errno);
3399 : : }
3400 : :
3401 : 12324 : return rc;
3402 : : }
3403 : :
3404 : : static int
3405 : 21102261 : nvmf_tcp_req_complete(struct spdk_nvmf_request *req)
3406 : : {
3407 : : struct spdk_nvmf_tcp_transport *ttransport;
3408 : : struct spdk_nvmf_tcp_req *tcp_req;
3409 : :
3410 : 21102261 : ttransport = SPDK_CONTAINEROF(req->qpair->transport, struct spdk_nvmf_tcp_transport, transport);
3411 : 21102261 : tcp_req = SPDK_CONTAINEROF(req, struct spdk_nvmf_tcp_req, req);
3412 : :
3413 [ + + + - ]: 21102261 : switch (tcp_req->state) {
3414 : 19769005 : case TCP_REQUEST_STATE_EXECUTING:
3415 : : case TCP_REQUEST_STATE_AWAITING_ZCOPY_COMMIT:
3416 : 19769005 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_EXECUTED);
3417 : 19769005 : break;
3418 : 905663 : case TCP_REQUEST_STATE_AWAITING_ZCOPY_START:
3419 : 905663 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_ZCOPY_START_COMPLETED);
3420 : 905663 : break;
3421 : 427593 : case TCP_REQUEST_STATE_AWAITING_ZCOPY_RELEASE:
3422 : 427593 : nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_COMPLETED);
3423 : 427593 : break;
3424 : 0 : default:
3425 : 0 : SPDK_ERRLOG("Unexpected request state %d (cntlid:%d, qid:%d)\n",
3426 : : tcp_req->state, req->qpair->ctrlr->cntlid, req->qpair->qid);
3427 : 0 : assert(0 && "Unexpected request state");
3428 : : break;
3429 : : }
3430 : :
3431 : 21102261 : nvmf_tcp_req_process(ttransport, tcp_req);
3432 : :
3433 : 21102261 : return 0;
3434 : : }
3435 : :
3436 : : static void
3437 : 12324 : nvmf_tcp_close_qpair(struct spdk_nvmf_qpair *qpair,
3438 : : spdk_nvmf_transport_qpair_fini_cb cb_fn, void *cb_arg)
3439 : : {
3440 : : struct spdk_nvmf_tcp_qpair *tqpair;
3441 : :
3442 [ - + - + ]: 12324 : SPDK_DEBUGLOG(nvmf_tcp, "Qpair: %p\n", qpair);
3443 : :
3444 : 12324 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
3445 : :
3446 [ - + ]: 12324 : assert(tqpair->fini_cb_fn == NULL);
3447 : 12324 : tqpair->fini_cb_fn = cb_fn;
3448 : 12324 : tqpair->fini_cb_arg = cb_arg;
3449 : :
3450 : 12324 : nvmf_tcp_qpair_set_state(tqpair, NVME_TCP_QPAIR_STATE_EXITED);
3451 : 12324 : nvmf_tcp_qpair_destroy(tqpair);
3452 : 12324 : }
3453 : :
3454 : : static int
3455 : 971878745 : nvmf_tcp_poll_group_poll(struct spdk_nvmf_transport_poll_group *group)
3456 : : {
3457 : : struct spdk_nvmf_tcp_poll_group *tgroup;
3458 : 971878745 : int num_events, rc = 0, rc2;
3459 : : struct spdk_nvmf_tcp_qpair *tqpair, *tqpair_tmp;
3460 : :
3461 : 971878745 : tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group);
3462 : :
3463 [ + + + + ]: 971878745 : if (spdk_unlikely(TAILQ_EMPTY(&tgroup->qpairs) && TAILQ_EMPTY(&tgroup->await_req))) {
3464 : 443236675 : return 0;
3465 : : }
3466 : :
3467 : 528642070 : num_events = spdk_sock_group_poll(tgroup->sock_group);
3468 [ - + ]: 528642070 : if (spdk_unlikely(num_events < 0)) {
3469 : 0 : SPDK_ERRLOG("Failed to poll sock_group=%p\n", tgroup->sock_group);
3470 : : }
3471 : :
3472 [ + + ]: 529352414 : TAILQ_FOREACH_SAFE(tqpair, &tgroup->await_req, link, tqpair_tmp) {
3473 : 710344 : rc2 = nvmf_tcp_sock_process(tqpair);
3474 : :
3475 : : /* If there was a new socket error, disconnect */
3476 [ - + ]: 710344 : if (spdk_unlikely(rc2 < 0)) {
3477 : 0 : nvmf_tcp_qpair_disconnect(tqpair);
3478 [ # # ]: 0 : if (rc == 0) {
3479 : 0 : rc = rc2;
3480 : : }
3481 : : }
3482 : : }
3483 : :
3484 [ + - ]: 528642070 : return rc == 0 ? num_events : rc;
3485 : : }
3486 : :
3487 : : static int
3488 : 15772 : nvmf_tcp_qpair_get_trid(struct spdk_nvmf_qpair *qpair,
3489 : : struct spdk_nvme_transport_id *trid, bool peer)
3490 : : {
3491 : : struct spdk_nvmf_tcp_qpair *tqpair;
3492 : : uint16_t port;
3493 : :
3494 : 15772 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
3495 : 15772 : spdk_nvme_trid_populate_transport(trid, SPDK_NVME_TRANSPORT_TCP);
3496 : :
3497 [ + + ]: 15772 : if (peer) {
3498 [ - + ]: 370 : snprintf(trid->traddr, sizeof(trid->traddr), "%s", tqpair->initiator_addr);
3499 : 370 : port = tqpair->initiator_port;
3500 : : } else {
3501 [ - + ]: 15402 : snprintf(trid->traddr, sizeof(trid->traddr), "%s", tqpair->target_addr);
3502 : 15402 : port = tqpair->target_port;
3503 : : }
3504 : :
3505 [ + - ]: 15772 : if (spdk_sock_is_ipv4(tqpair->sock)) {
3506 : 15772 : trid->adrfam = SPDK_NVMF_ADRFAM_IPV4;
3507 [ # # ]: 0 : } else if (spdk_sock_is_ipv6(tqpair->sock)) {
3508 : 0 : trid->adrfam = SPDK_NVMF_ADRFAM_IPV6;
3509 : : } else {
3510 : 0 : return -1;
3511 : : }
3512 : :
3513 [ - + ]: 15772 : snprintf(trid->trsvcid, sizeof(trid->trsvcid), "%d", port);
3514 : 15772 : return 0;
3515 : : }
3516 : :
3517 : : static int
3518 : 0 : nvmf_tcp_qpair_get_local_trid(struct spdk_nvmf_qpair *qpair,
3519 : : struct spdk_nvme_transport_id *trid)
3520 : : {
3521 : 0 : return nvmf_tcp_qpair_get_trid(qpair, trid, 0);
3522 : : }
3523 : :
3524 : : static int
3525 : 370 : nvmf_tcp_qpair_get_peer_trid(struct spdk_nvmf_qpair *qpair,
3526 : : struct spdk_nvme_transport_id *trid)
3527 : : {
3528 : 370 : return nvmf_tcp_qpair_get_trid(qpair, trid, 1);
3529 : : }
3530 : :
3531 : : static int
3532 : 15402 : nvmf_tcp_qpair_get_listen_trid(struct spdk_nvmf_qpair *qpair,
3533 : : struct spdk_nvme_transport_id *trid)
3534 : : {
3535 : 15402 : return nvmf_tcp_qpair_get_trid(qpair, trid, 0);
3536 : : }
3537 : :
3538 : : static void
3539 : 0 : nvmf_tcp_req_set_abort_status(struct spdk_nvmf_request *req,
3540 : : struct spdk_nvmf_tcp_req *tcp_req_to_abort)
3541 : : {
3542 : 0 : nvmf_tcp_req_set_cpl(tcp_req_to_abort, SPDK_NVME_SCT_GENERIC, SPDK_NVME_SC_ABORTED_BY_REQUEST);
3543 : 0 : nvmf_tcp_req_set_state(tcp_req_to_abort, TCP_REQUEST_STATE_READY_TO_COMPLETE);
3544 : :
3545 : 0 : req->rsp->nvme_cpl.cdw0 &= ~1U; /* Command was successfully aborted. */
3546 : 0 : }
3547 : :
3548 : : static int
3549 : 79555 : _nvmf_tcp_qpair_abort_request(void *ctx)
3550 : : {
3551 : 79555 : struct spdk_nvmf_request *req = ctx;
3552 : 79555 : struct spdk_nvmf_tcp_req *tcp_req_to_abort = SPDK_CONTAINEROF(req->req_to_abort,
3553 : : struct spdk_nvmf_tcp_req, req);
3554 : 79555 : struct spdk_nvmf_tcp_qpair *tqpair = SPDK_CONTAINEROF(req->req_to_abort->qpair,
3555 : : struct spdk_nvmf_tcp_qpair, qpair);
3556 : 79555 : struct spdk_nvmf_tcp_transport *ttransport = SPDK_CONTAINEROF(tqpair->qpair.transport,
3557 : : struct spdk_nvmf_tcp_transport, transport);
3558 : : int rc;
3559 : :
3560 : 79555 : spdk_poller_unregister(&req->poller);
3561 : :
3562 [ + - + + ]: 79555 : switch (tcp_req_to_abort->state) {
3563 : 75718 : case TCP_REQUEST_STATE_EXECUTING:
3564 : : case TCP_REQUEST_STATE_AWAITING_ZCOPY_START:
3565 : : case TCP_REQUEST_STATE_AWAITING_ZCOPY_COMMIT:
3566 : 75718 : rc = nvmf_ctrlr_abort_request(req);
3567 [ + - ]: 75718 : if (rc == SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS) {
3568 : 75718 : return SPDK_POLLER_BUSY;
3569 : : }
3570 : 0 : break;
3571 : :
3572 : 0 : case TCP_REQUEST_STATE_NEED_BUFFER:
3573 : 0 : nvmf_tcp_request_get_buffers_abort(tcp_req_to_abort);
3574 : 0 : nvmf_tcp_req_set_abort_status(req, tcp_req_to_abort);
3575 : 0 : nvmf_tcp_req_process(ttransport, tcp_req_to_abort);
3576 : 0 : break;
3577 : :
3578 : 1151 : case TCP_REQUEST_STATE_AWAITING_R2T_ACK:
3579 : : case TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER:
3580 [ + - ]: 1151 : if (spdk_get_ticks() < req->timeout_tsc) {
3581 : 1151 : req->poller = SPDK_POLLER_REGISTER(_nvmf_tcp_qpair_abort_request, req, 0);
3582 : 1151 : return SPDK_POLLER_BUSY;
3583 : : }
3584 : 0 : break;
3585 : :
3586 : 2686 : default:
3587 : : /* Requests in other states are either un-abortable (e.g.
3588 : : * TRANSFERRING_CONTROLLER_TO_HOST) or should never end up here, as they're
3589 : : * immediately transitioned to other states in nvmf_tcp_req_process() (e.g.
3590 : : * READY_TO_EXECUTE). But it is fine to end up here, as we'll simply complete the
3591 : : * abort request with the bit0 of dword0 set (command not aborted).
3592 : : */
3593 : 2686 : break;
3594 : : }
3595 : :
3596 : 2686 : spdk_nvmf_request_complete(req);
3597 : 2686 : return SPDK_POLLER_BUSY;
3598 : : }
3599 : :
3600 : : static void
3601 : 83704 : nvmf_tcp_qpair_abort_request(struct spdk_nvmf_qpair *qpair,
3602 : : struct spdk_nvmf_request *req)
3603 : : {
3604 : : struct spdk_nvmf_tcp_qpair *tqpair;
3605 : : struct spdk_nvmf_tcp_transport *ttransport;
3606 : : struct spdk_nvmf_transport *transport;
3607 : : uint16_t cid;
3608 : : uint32_t i;
3609 : 83704 : struct spdk_nvmf_tcp_req *tcp_req_to_abort = NULL;
3610 : :
3611 : 83704 : tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair);
3612 : 83704 : ttransport = SPDK_CONTAINEROF(qpair->transport, struct spdk_nvmf_tcp_transport, transport);
3613 : 83704 : transport = &ttransport->transport;
3614 : :
3615 : 83704 : cid = req->cmd->nvme_cmd.cdw10_bits.abort.cid;
3616 : :
3617 [ + + ]: 4896495 : for (i = 0; i < tqpair->resource_count; i++) {
3618 [ + + ]: 4891195 : if (tqpair->reqs[i].state != TCP_REQUEST_STATE_FREE &&
3619 [ + + ]: 2495247 : tqpair->reqs[i].req.cmd->nvme_cmd.cid == cid) {
3620 : 78404 : tcp_req_to_abort = &tqpair->reqs[i];
3621 : 78404 : break;
3622 : : }
3623 : : }
3624 : :
3625 [ + - + - ]: 83704 : spdk_trace_record(TRACE_TCP_QP_ABORT_REQ, tqpair->qpair.trace_id, 0, (uintptr_t)req);
3626 : :
3627 [ + + ]: 83704 : if (tcp_req_to_abort == NULL) {
3628 : 5300 : spdk_nvmf_request_complete(req);
3629 : 5300 : return;
3630 : : }
3631 : :
3632 : 78404 : req->req_to_abort = &tcp_req_to_abort->req;
3633 : 156808 : req->timeout_tsc = spdk_get_ticks() +
3634 : 78404 : transport->opts.abort_timeout_sec * spdk_get_ticks_hz();
3635 : 78404 : req->poller = NULL;
3636 : :
3637 : 78404 : _nvmf_tcp_qpair_abort_request(req);
3638 : : }
3639 : :
3640 : : struct tcp_subsystem_add_host_opts {
3641 : : char *psk;
3642 : : };
3643 : :
3644 : : static const struct spdk_json_object_decoder tcp_subsystem_add_host_opts_decoder[] = {
3645 : : {"psk", offsetof(struct tcp_subsystem_add_host_opts, psk), spdk_json_decode_string, true},
3646 : : };
3647 : :
3648 : : static int
3649 : 45 : tcp_load_psk(const char *fname, char *buf, size_t bufsz)
3650 : : {
3651 : : FILE *psk_file;
3652 : 3 : struct stat statbuf;
3653 : : int rc;
3654 : :
3655 [ - + - + : 45 : if (stat(fname, &statbuf) != 0) {
- + ]
3656 : 0 : SPDK_ERRLOG("Could not read permissions for PSK file\n");
3657 : 0 : return -EACCES;
3658 : : }
3659 : :
3660 [ + + ]: 45 : if ((statbuf.st_mode & TCP_PSK_INVALID_PERMISSIONS) != 0) {
3661 : 5 : SPDK_ERRLOG("Incorrect permissions for PSK file\n");
3662 : 5 : return -EPERM;
3663 : : }
3664 [ - + ]: 40 : if ((size_t)statbuf.st_size > bufsz) {
3665 : 0 : SPDK_ERRLOG("Invalid PSK: too long\n");
3666 : 0 : return -EINVAL;
3667 : : }
3668 : 40 : psk_file = fopen(fname, "r");
3669 [ - + ]: 40 : if (psk_file == NULL) {
3670 : 0 : SPDK_ERRLOG("Could not open PSK file\n");
3671 : 0 : return -EINVAL;
3672 : : }
3673 : :
3674 : 40 : rc = fread(buf, 1, statbuf.st_size, psk_file);
3675 [ - + ]: 40 : if (rc != statbuf.st_size) {
3676 : 0 : SPDK_ERRLOG("Failed to read PSK\n");
3677 : 0 : fclose(psk_file);
3678 : 0 : return -EINVAL;
3679 : : }
3680 : :
3681 : 40 : fclose(psk_file);
3682 : 40 : return 0;
3683 : : }
3684 : :
3685 [ - + ]: 965 : SPDK_LOG_DEPRECATION_REGISTER(nvmf_tcp_psk_path, "PSK path", "v24.09", 0);
3686 : :
3687 : : static int
3688 : 489 : nvmf_tcp_subsystem_add_host(struct spdk_nvmf_transport *transport,
3689 : : const struct spdk_nvmf_subsystem *subsystem,
3690 : : const char *hostnqn,
3691 : : const struct spdk_json_val *transport_specific)
3692 : : {
3693 : 5 : struct tcp_subsystem_add_host_opts opts;
3694 : : struct spdk_nvmf_tcp_transport *ttransport;
3695 : 489 : struct tcp_psk_entry *tmp, *entry = NULL;
3696 : 489 : uint8_t psk_configured[SPDK_TLS_PSK_MAX_LEN] = {};
3697 : 489 : char psk_interchange[SPDK_TLS_PSK_MAX_LEN + 1] = {};
3698 : : uint8_t tls_cipher_suite;
3699 : 489 : int rc = 0;
3700 : 5 : uint8_t psk_retained_hash;
3701 : 5 : uint64_t psk_configured_size;
3702 : :
3703 [ - + ]: 489 : if (transport_specific == NULL) {
3704 : 0 : return 0;
3705 : : }
3706 : :
3707 [ - + ]: 489 : assert(transport != NULL);
3708 [ - + ]: 489 : assert(subsystem != NULL);
3709 : :
3710 : 489 : memset(&opts, 0, sizeof(opts));
3711 : :
3712 : : /* Decode PSK (either name of a key or file path) */
3713 [ - + ]: 489 : if (spdk_json_decode_object_relaxed(transport_specific, tcp_subsystem_add_host_opts_decoder,
3714 : : SPDK_COUNTOF(tcp_subsystem_add_host_opts_decoder), &opts)) {
3715 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
3716 : 0 : return -EINVAL;
3717 : : }
3718 : :
3719 [ + + ]: 489 : if (opts.psk == NULL) {
3720 : 431 : return 0;
3721 : : }
3722 : :
3723 : 58 : entry = calloc(1, sizeof(struct tcp_psk_entry));
3724 [ - + ]: 58 : if (entry == NULL) {
3725 : 0 : SPDK_ERRLOG("Unable to allocate memory for PSK entry!\n");
3726 : 0 : rc = -ENOMEM;
3727 : 0 : goto end;
3728 : : }
3729 : :
3730 : 58 : entry->key = spdk_keyring_get_key(opts.psk);
3731 [ + + ]: 58 : if (entry->key != NULL) {
3732 : 13 : rc = spdk_key_get_key(entry->key, psk_interchange, SPDK_TLS_PSK_MAX_LEN);
3733 [ - + ]: 13 : if (rc < 0) {
3734 : 0 : SPDK_ERRLOG("Failed to retreive PSK '%s'\n", opts.psk);
3735 : 0 : rc = -EINVAL;
3736 : 0 : goto end;
3737 : : }
3738 : : } else {
3739 [ - + - + ]: 45 : if (strlen(opts.psk) >= sizeof(entry->psk)) {
3740 : 0 : SPDK_ERRLOG("PSK path too long\n");
3741 : 0 : rc = -EINVAL;
3742 : 0 : goto end;
3743 : : }
3744 : :
3745 : 45 : rc = tcp_load_psk(opts.psk, psk_interchange, SPDK_TLS_PSK_MAX_LEN);
3746 [ + + ]: 45 : if (rc) {
3747 : 5 : SPDK_ERRLOG("Could not retrieve PSK from file\n");
3748 : 5 : goto end;
3749 : : }
3750 : :
3751 : 40 : SPDK_LOG_DEPRECATED(nvmf_tcp_psk_path);
3752 : : }
3753 : :
3754 : : /* Parse PSK interchange to get length of base64 encoded data.
3755 : : * This is then used to decide which cipher suite should be used
3756 : : * to generate PSK identity and TLS PSK later on. */
3757 : 53 : rc = nvme_tcp_parse_interchange_psk(psk_interchange, psk_configured, sizeof(psk_configured),
3758 : : &psk_configured_size, &psk_retained_hash);
3759 [ - + ]: 53 : if (rc < 0) {
3760 : 0 : SPDK_ERRLOG("Failed to parse PSK interchange!\n");
3761 : 0 : goto end;
3762 : : }
3763 : :
3764 : : /* The Base64 string encodes the configured PSK (32 or 48 bytes binary).
3765 : : * This check also ensures that psk_configured_size is smaller than
3766 : : * psk_retained buffer size. */
3767 [ + + ]: 53 : if (psk_configured_size == SHA256_DIGEST_LENGTH) {
3768 : 23 : tls_cipher_suite = NVME_TCP_CIPHER_AES_128_GCM_SHA256;
3769 [ + - ]: 30 : } else if (psk_configured_size == SHA384_DIGEST_LENGTH) {
3770 : 30 : tls_cipher_suite = NVME_TCP_CIPHER_AES_256_GCM_SHA384;
3771 : : } else {
3772 : 0 : SPDK_ERRLOG("Unrecognized cipher suite!\n");
3773 : 0 : rc = -EINVAL;
3774 : 0 : goto end;
3775 : : }
3776 : :
3777 : 53 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
3778 : : /* Generate PSK identity. */
3779 : 53 : rc = nvme_tcp_generate_psk_identity(entry->pskid, sizeof(entry->pskid), hostnqn,
3780 : 53 : subsystem->subnqn, tls_cipher_suite);
3781 [ - + ]: 53 : if (rc) {
3782 : 0 : rc = -EINVAL;
3783 : 0 : goto end;
3784 : : }
3785 : : /* Check if PSK identity entry already exists. */
3786 [ - + ]: 53 : TAILQ_FOREACH(tmp, &ttransport->psks, link) {
3787 [ # # # # : 0 : if (strncmp(tmp->pskid, entry->pskid, NVMF_PSK_IDENTITY_LEN) == 0) {
# # ]
3788 : 0 : SPDK_ERRLOG("Given PSK identity: %s entry already exists!\n", entry->pskid);
3789 : 0 : rc = -EEXIST;
3790 : 0 : goto end;
3791 : : }
3792 : : }
3793 : :
3794 [ - + ]: 53 : if (snprintf(entry->hostnqn, sizeof(entry->hostnqn), "%s", hostnqn) < 0) {
3795 : 0 : SPDK_ERRLOG("Could not write hostnqn string!\n");
3796 : 0 : rc = -EINVAL;
3797 : 0 : goto end;
3798 : : }
3799 [ - + ]: 53 : if (snprintf(entry->subnqn, sizeof(entry->subnqn), "%s", subsystem->subnqn) < 0) {
3800 : 0 : SPDK_ERRLOG("Could not write subnqn string!\n");
3801 : 0 : rc = -EINVAL;
3802 : 0 : goto end;
3803 : : }
3804 : :
3805 : 53 : entry->tls_cipher_suite = tls_cipher_suite;
3806 : :
3807 : : /* No hash indicates that Configured PSK must be used as Retained PSK. */
3808 [ + + ]: 53 : if (psk_retained_hash == NVME_TCP_HASH_ALGORITHM_NONE) {
3809 : : /* Psk configured is either 32 or 48 bytes long. */
3810 [ - + ]: 6 : memcpy(entry->psk, psk_configured, psk_configured_size);
3811 : 6 : entry->psk_size = psk_configured_size;
3812 : : } else {
3813 : : /* Derive retained PSK. */
3814 : 47 : rc = nvme_tcp_derive_retained_psk(psk_configured, psk_configured_size, hostnqn, entry->psk,
3815 : : SPDK_TLS_PSK_MAX_LEN, psk_retained_hash);
3816 [ - + ]: 47 : if (rc < 0) {
3817 : 0 : SPDK_ERRLOG("Unable to derive retained PSK!\n");
3818 : 0 : goto end;
3819 : : }
3820 : 47 : entry->psk_size = rc;
3821 : : }
3822 : :
3823 [ + + ]: 53 : if (entry->key == NULL) {
3824 : 40 : rc = snprintf(entry->psk_path, sizeof(entry->psk_path), "%s", opts.psk);
3825 [ + - - + ]: 40 : if (rc < 0 || (size_t)rc >= sizeof(entry->psk_path)) {
3826 : 0 : SPDK_ERRLOG("Could not save PSK path!\n");
3827 : 0 : rc = -ENAMETOOLONG;
3828 : 0 : goto end;
3829 : : }
3830 : : }
3831 : :
3832 : 53 : TAILQ_INSERT_TAIL(&ttransport->psks, entry, link);
3833 : 53 : rc = 0;
3834 : :
3835 : 58 : end:
3836 : 58 : spdk_memset_s(psk_configured, sizeof(psk_configured), 0, sizeof(psk_configured));
3837 : 58 : spdk_memset_s(psk_interchange, sizeof(psk_interchange), 0, sizeof(psk_interchange));
3838 : :
3839 : 58 : free(opts.psk);
3840 [ + + ]: 58 : if (rc != 0) {
3841 : 5 : nvmf_tcp_free_psk_entry(entry);
3842 : : }
3843 : :
3844 : 58 : return rc;
3845 : : }
3846 : :
3847 : : static void
3848 : 489 : nvmf_tcp_subsystem_remove_host(struct spdk_nvmf_transport *transport,
3849 : : const struct spdk_nvmf_subsystem *subsystem,
3850 : : const char *hostnqn)
3851 : : {
3852 : : struct spdk_nvmf_tcp_transport *ttransport;
3853 : : struct tcp_psk_entry *entry, *tmp;
3854 : :
3855 [ - + ]: 489 : assert(transport != NULL);
3856 [ - + ]: 489 : assert(subsystem != NULL);
3857 : :
3858 : 489 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
3859 [ + + ]: 489 : TAILQ_FOREACH_SAFE(entry, &ttransport->psks, link, tmp) {
3860 [ + + - + : 53 : if ((strncmp(entry->hostnqn, hostnqn, SPDK_NVMF_NQN_MAX_LEN)) == 0 &&
+ - ]
3861 [ + + - + : 53 : (strncmp(entry->subnqn, subsystem->subnqn, SPDK_NVMF_NQN_MAX_LEN)) == 0) {
+ - ]
3862 [ - + ]: 53 : TAILQ_REMOVE(&ttransport->psks, entry, link);
3863 : 53 : nvmf_tcp_free_psk_entry(entry);
3864 : 53 : break;
3865 : : }
3866 : : }
3867 : 489 : }
3868 : :
3869 : : static void
3870 : 10 : nvmf_tcp_subsystem_dump_host(struct spdk_nvmf_transport *transport,
3871 : : const struct spdk_nvmf_subsystem *subsystem, const char *hostnqn,
3872 : : struct spdk_json_write_ctx *w)
3873 : : {
3874 : : struct spdk_nvmf_tcp_transport *ttransport;
3875 : : struct tcp_psk_entry *entry;
3876 : :
3877 [ - + ]: 10 : assert(transport != NULL);
3878 [ - + ]: 10 : assert(subsystem != NULL);
3879 : :
3880 : 10 : ttransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_tcp_transport, transport);
3881 [ + - ]: 10 : TAILQ_FOREACH(entry, &ttransport->psks, link) {
3882 [ - + - + : 10 : if ((strncmp(entry->hostnqn, hostnqn, SPDK_NVMF_NQN_MAX_LEN)) == 0 &&
+ - ]
3883 [ - + - + : 10 : (strncmp(entry->subnqn, subsystem->subnqn, SPDK_NVMF_NQN_MAX_LEN)) == 0) {
+ - ]
3884 [ + + ]: 15 : spdk_json_write_named_string(w, "psk", entry->key ?
3885 : 5 : spdk_key_get_name(entry->key) : entry->psk_path);
3886 : 10 : break;
3887 : : }
3888 : : }
3889 : 10 : }
3890 : :
3891 : : static void
3892 : 315 : nvmf_tcp_opts_init(struct spdk_nvmf_transport_opts *opts)
3893 : : {
3894 : 315 : opts->max_queue_depth = SPDK_NVMF_TCP_DEFAULT_MAX_IO_QUEUE_DEPTH;
3895 : 315 : opts->max_qpairs_per_ctrlr = SPDK_NVMF_TCP_DEFAULT_MAX_QPAIRS_PER_CTRLR;
3896 : 315 : opts->in_capsule_data_size = SPDK_NVMF_TCP_DEFAULT_IN_CAPSULE_DATA_SIZE;
3897 : 315 : opts->max_io_size = SPDK_NVMF_TCP_DEFAULT_MAX_IO_SIZE;
3898 : 315 : opts->io_unit_size = SPDK_NVMF_TCP_DEFAULT_IO_UNIT_SIZE;
3899 : 315 : opts->max_aq_depth = SPDK_NVMF_TCP_DEFAULT_MAX_ADMIN_QUEUE_DEPTH;
3900 : 315 : opts->num_shared_buffers = SPDK_NVMF_TCP_DEFAULT_NUM_SHARED_BUFFERS;
3901 : 315 : opts->buf_cache_size = SPDK_NVMF_TCP_DEFAULT_BUFFER_CACHE_SIZE;
3902 : 315 : opts->dif_insert_or_strip = SPDK_NVMF_TCP_DEFAULT_DIF_INSERT_OR_STRIP;
3903 : 315 : opts->abort_timeout_sec = SPDK_NVMF_TCP_DEFAULT_ABORT_TIMEOUT_SEC;
3904 : 315 : opts->transport_specific = NULL;
3905 : 315 : }
3906 : :
3907 : : const struct spdk_nvmf_transport_ops spdk_nvmf_transport_tcp = {
3908 : : .name = "TCP",
3909 : : .type = SPDK_NVME_TRANSPORT_TCP,
3910 : : .opts_init = nvmf_tcp_opts_init,
3911 : : .create = nvmf_tcp_create,
3912 : : .dump_opts = nvmf_tcp_dump_opts,
3913 : : .destroy = nvmf_tcp_destroy,
3914 : :
3915 : : .listen = nvmf_tcp_listen,
3916 : : .stop_listen = nvmf_tcp_stop_listen,
3917 : :
3918 : : .listener_discover = nvmf_tcp_discover,
3919 : :
3920 : : .poll_group_create = nvmf_tcp_poll_group_create,
3921 : : .get_optimal_poll_group = nvmf_tcp_get_optimal_poll_group,
3922 : : .poll_group_destroy = nvmf_tcp_poll_group_destroy,
3923 : : .poll_group_add = nvmf_tcp_poll_group_add,
3924 : : .poll_group_remove = nvmf_tcp_poll_group_remove,
3925 : : .poll_group_poll = nvmf_tcp_poll_group_poll,
3926 : :
3927 : : .req_free = nvmf_tcp_req_free,
3928 : : .req_complete = nvmf_tcp_req_complete,
3929 : : .req_get_buffers = nvmf_tcp_req_get_buffers,
3930 : :
3931 : : .qpair_fini = nvmf_tcp_close_qpair,
3932 : : .qpair_get_local_trid = nvmf_tcp_qpair_get_local_trid,
3933 : : .qpair_get_peer_trid = nvmf_tcp_qpair_get_peer_trid,
3934 : : .qpair_get_listen_trid = nvmf_tcp_qpair_get_listen_trid,
3935 : : .qpair_abort_request = nvmf_tcp_qpair_abort_request,
3936 : : .subsystem_add_host = nvmf_tcp_subsystem_add_host,
3937 : : .subsystem_remove_host = nvmf_tcp_subsystem_remove_host,
3938 : : .subsystem_dump_host = nvmf_tcp_subsystem_dump_host,
3939 : : };
3940 : :
3941 : 965 : SPDK_NVMF_TRANSPORT_REGISTER(tcp, &spdk_nvmf_transport_tcp);
3942 : 965 : SPDK_LOG_REGISTER_COMPONENT(nvmf_tcp)
|