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