LCOV - code coverage report
Current view: top level - spdk/lib/nvme - nvme_ctrlr_ocssd_cmd.c (source / functions) Hit Total Coverage
Test: Combined Lines: 20 24 83.3 %
Date: 2024-07-12 15:16:49 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 16 56.2 %

           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) 2021 Mellanox Technologies LTD. All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/nvme_ocssd.h"
       7                 :            : #include "nvme_internal.h"
       8                 :            : 
       9                 :            : bool
      10                 :       2048 : spdk_nvme_ctrlr_is_ocssd_supported(struct spdk_nvme_ctrlr *ctrlr)
      11                 :            : {
      12         [ +  + ]:       2048 :         if (ctrlr->quirks & NVME_QUIRK_OCSSD) {
      13                 :            :                 /* TODO: There isn't a standardized way to identify Open-Channel SSD
      14                 :            :                  * different verdors may have different conditions.
      15                 :            :                  */
      16                 :            : 
      17                 :            :                 /*
      18                 :            :                  * Current QEMU OpenChannel Device needs to check nsdata->vs[0].
      19                 :            :                  * Here check nsdata->vs[0] of the first namespace.
      20                 :            :                  */
      21         [ +  - ]:          6 :                 if (ctrlr->cdata.vid == SPDK_PCI_VID_CNEXLABS) {
      22                 :          6 :                         uint32_t nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr);
      23                 :            :                         struct spdk_nvme_ns *ns;
      24                 :            : 
      25         [ -  + ]:          6 :                         if (nsid == 0) {
      26                 :          0 :                                 return false;
      27                 :            :                         }
      28                 :            : 
      29                 :          6 :                         ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
      30                 :            : 
      31   [ +  -  +  - ]:          6 :                         if (ns && ns->nsdata.vendor_specific[0] == 0x1) {
      32                 :          6 :                                 return true;
      33                 :            :                         }
      34                 :            :                 }
      35                 :            :         }
      36                 :       2042 :         return false;
      37                 :            : }
      38                 :            : 
      39                 :            : 
      40                 :            : int
      41                 :          6 : spdk_nvme_ocssd_ctrlr_cmd_geometry(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
      42                 :            :                                    void *payload, uint32_t payload_size,
      43                 :            :                                    spdk_nvme_cmd_cb cb_fn, void *cb_arg)
      44                 :            : {
      45                 :            :         struct nvme_request *req;
      46                 :            :         struct spdk_nvme_cmd *cmd;
      47                 :            :         int rc;
      48                 :            : 
      49   [ +  -  -  + ]:          6 :         if (!payload || (payload_size != sizeof(struct spdk_ocssd_geometry_data))) {
      50                 :          0 :                 return -EINVAL;
      51                 :            :         }
      52                 :            : 
      53                 :          6 :         nvme_ctrlr_lock(ctrlr);
      54                 :          6 :         req = nvme_allocate_request_user_copy(ctrlr->adminq,
      55                 :            :                                               payload, payload_size, cb_fn, cb_arg, false);
      56         [ -  + ]:          6 :         if (req == NULL) {
      57                 :          0 :                 nvme_ctrlr_unlock(ctrlr);
      58                 :          0 :                 return -ENOMEM;
      59                 :            :         }
      60                 :            : 
      61                 :          6 :         cmd = &req->cmd;
      62                 :          6 :         cmd->opc = SPDK_OCSSD_OPC_GEOMETRY;
      63                 :          6 :         cmd->nsid = nsid;
      64                 :            : 
      65                 :          6 :         rc = nvme_ctrlr_submit_admin_request(ctrlr, req);
      66                 :            : 
      67                 :          6 :         nvme_ctrlr_unlock(ctrlr);
      68                 :          6 :         return rc;
      69                 :            : }

Generated by: LCOV version 1.14