LCOV - code coverage report
Current view: top level - spdk/lib/nvme - nvme_tcp.c (source / functions) Hit Total Coverage
Test: Combined Lines: 1288 1735 74.2 %
Date: 2024-12-15 22:36:43 Functions: 86 96 89.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1873 6604 28.4 %

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

Generated by: LCOV version 1.15