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/log.h" 8 #include "spdk/env.h" 9 #include "spdk/vmd.h" 10 11 struct spdk_pci_addr g_probe_addr; 12 13 static int 14 parse_args(int argc, char **argv) 15 { 16 int op; 17 18 while ((op = getopt(argc, argv, "r:d")) != -1) { 19 switch (op) { 20 case 'r': 21 if (spdk_pci_addr_parse(&g_probe_addr, optarg)) { 22 SPDK_ERRLOG("Error parsing PCI address\n"); 23 return 1; 24 } 25 26 break; 27 28 case 'd': 29 spdk_log_set_print_level(SPDK_LOG_DEBUG); 30 spdk_log_set_flag("vmd"); 31 break; 32 33 default: 34 return 1; 35 } 36 } 37 38 return 0; 39 } 40 41 static void 42 print_device(void *ctx, struct spdk_pci_device *pci_device) 43 { 44 char addr_buf[128]; 45 int rc; 46 47 if (strcmp(spdk_pci_device_get_type(pci_device), "vmd") == 0) { 48 rc = spdk_pci_addr_fmt(addr_buf, sizeof(addr_buf), &pci_device->addr); 49 if (rc != 0) { 50 fprintf(stderr, "Failed to format VMD's PCI address\n"); 51 return; 52 } 53 54 printf("%s\n", addr_buf); 55 } 56 } 57 58 int 59 main(int argc, char **argv) 60 { 61 struct spdk_env_opts opts; 62 int rc; 63 64 rc = parse_args(argc, argv); 65 if (rc != 0) { 66 return rc; 67 } 68 69 spdk_env_opts_init(&opts); 70 opts.name = "lsvmd"; 71 72 if (spdk_env_init(&opts) < 0) { 73 SPDK_ERRLOG("Unable to initialize SPDK env\n"); 74 return 1; 75 } 76 77 rc = spdk_vmd_init(); 78 if (rc) { 79 SPDK_ERRLOG("No VMD Controllers found\n"); 80 } 81 82 spdk_pci_for_each_device(NULL, print_device); 83 84 spdk_vmd_fini(); 85 86 spdk_env_fini(); 87 return rc; 88 } 89