LCOV - code coverage report
Current view: top level - spdk/app/spdk_lspci - spdk_lspci.c (source / functions) Hit Total Coverage
Test: Combined Lines: 0 47 0.0 %
Date: 2024-07-10 15:22:03 Functions: 0 4 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 32 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2019 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk/env.h"
       8                 :            : #include "spdk/vmd.h"
       9                 :            : 
      10                 :            : static void
      11                 :          0 : usage(void)
      12                 :            : {
      13         [ #  # ]:          0 :         printf("Usage: spdk_lspci\n");
      14         [ #  # ]:          0 :         printf("Print available SPDK PCI devices supported by NVMe driver.\n");
      15                 :          0 : }
      16                 :            : 
      17                 :            : static int
      18                 :          0 : pci_enum_cb(void *ctx, struct spdk_pci_device *dev)
      19                 :            : {
      20                 :          0 :         return 0;
      21                 :            : }
      22                 :            : 
      23                 :            : static void
      24                 :          0 : print_pci_dev(void *ctx, struct spdk_pci_device *dev)
      25                 :            : {
      26                 :          0 :         struct spdk_pci_addr pci_addr = spdk_pci_device_get_addr(dev);
      27                 :          0 :         char addr[32] = { 0 };
      28                 :            : 
      29                 :          0 :         spdk_pci_addr_fmt(addr, sizeof(addr), &pci_addr);
      30                 :            : 
      31                 :          0 :         printf("%s (%x %x)", addr,
      32                 :          0 :                spdk_pci_device_get_vendor_id(dev),
      33                 :          0 :                spdk_pci_device_get_device_id(dev));
      34                 :            : 
      35   [ #  #  #  # ]:          0 :         if (strcmp(spdk_pci_device_get_type(dev), "vmd") == 0) {
      36                 :          0 :                 printf(" (NVMe disk behind VMD) ");
      37                 :            :         }
      38                 :            : 
      39         [ #  # ]:          0 :         if (dev->internal.driver == spdk_pci_vmd_get_driver()) {
      40                 :          0 :                 printf(" (VMD) ");
      41                 :            :         }
      42                 :            : 
      43                 :          0 :         printf("\n");
      44                 :          0 : }
      45                 :            : 
      46                 :            : int
      47                 :          0 : main(int argc, char **argv)
      48                 :            : {
      49                 :          0 :         int op, rc = 0;
      50                 :          0 :         struct spdk_env_opts opts;
      51                 :            : 
      52   [ #  #  #  #  :          0 :         while ((op = getopt(argc, argv, "h")) != -1) {
                   #  # ]
      53         [ #  # ]:          0 :                 switch (op) {
      54                 :          0 :                 case 'h':
      55                 :          0 :                         usage();
      56                 :          0 :                         return 0;
      57                 :          0 :                 default:
      58                 :          0 :                         usage();
      59                 :          0 :                         return 1;
      60                 :            :                 }
      61                 :            :         }
      62                 :            : 
      63                 :          0 :         spdk_env_opts_init(&opts);
      64                 :          0 :         opts.name = "spdk_lspci";
      65                 :            : 
      66         [ #  # ]:          0 :         if (spdk_env_init(&opts) < 0) {
      67         [ #  # ]:          0 :                 printf("Unable to initialize SPDK env\n");
      68                 :          0 :                 return 1;
      69                 :            :         }
      70                 :            : 
      71         [ #  # ]:          0 :         if (spdk_vmd_init()) {
      72         [ #  # ]:          0 :                 printf("Failed to initialize VMD. Some NVMe devices can be unavailable.\n");
      73                 :            :         }
      74                 :            : 
      75         [ #  # ]:          0 :         if (spdk_pci_enumerate(spdk_pci_nvme_get_driver(), pci_enum_cb, NULL)) {
      76         [ #  # ]:          0 :                 printf("Unable to enumerate PCI nvme driver\n");
      77                 :          0 :                 rc = 1;
      78                 :          0 :                 goto exit;
      79                 :            :         }
      80                 :            : 
      81         [ #  # ]:          0 :         printf("\nList of available PCI devices:\n");
      82                 :          0 :         spdk_pci_for_each_device(NULL, print_pci_dev);
      83                 :            : 
      84                 :          0 : exit:
      85                 :          0 :         spdk_vmd_fini();
      86                 :          0 :         spdk_env_fini();
      87                 :            : 
      88                 :          0 :         return rc;
      89                 :            : }

Generated by: LCOV version 1.14