1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2019 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 /** \file 7 * VMD driver public interface 8 */ 9 10 #ifndef SPDK_VMD_H 11 #define SPDK_VMD_H 12 13 #include "spdk/stdinc.h" 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 #include "spdk/env.h" 20 21 /* Maximum VMD devices - up to 6 per cpu */ 22 #define MAX_VMD_TARGET 24 23 24 /** 25 * Enumerate VMD devices and hook them into the spdk pci subsystem 26 * 27 * \return 0 on success, -1 on failure 28 */ 29 int spdk_vmd_init(void); 30 31 /** 32 * Release any resources allocated by the VMD library via spdk_vmd_init(). 33 */ 34 void spdk_vmd_fini(void); 35 36 /** 37 * Returns a list of nvme devices found on the given vmd pci BDF. 38 * 39 * \param vmd_addr pci BDF of the vmd device to return end device list 40 * \param nvme_list buffer of exactly MAX_VMD_TARGET to return spdk_pci_device array. 41 * 42 * \return Returns count of nvme device attached to input VMD. 43 */ 44 int spdk_vmd_pci_device_list(struct spdk_pci_addr vmd_addr, struct spdk_pci_device *nvme_list); 45 46 /** State of the LEDs */ 47 enum spdk_vmd_led_state { 48 SPDK_VMD_LED_STATE_OFF, 49 SPDK_VMD_LED_STATE_IDENTIFY, 50 SPDK_VMD_LED_STATE_FAULT, 51 SPDK_VMD_LED_STATE_REBUILD, 52 SPDK_VMD_LED_STATE_UNKNOWN, 53 }; 54 55 /** 56 * Sets the state of the LED on specified PCI device. The device needs to be behind VMD. 57 * 58 * \param pci_device PCI device 59 * \param state LED state to set 60 * 61 * \return 0 on success, negative errno otherwise 62 */ 63 int spdk_vmd_set_led_state(struct spdk_pci_device *pci_device, enum spdk_vmd_led_state state); 64 65 /** 66 * Retrieves the state of the LED on specified PCI device. The device needs to be behind VMD. 67 * 68 * \param pci_device PCI device 69 * \param state current LED state 70 * 71 * \return 0 on success, negative errno otherwise 72 */ 73 int spdk_vmd_get_led_state(struct spdk_pci_device *pci_device, enum spdk_vmd_led_state *state); 74 75 /** 76 * Checks for hotplug/hotremove events of the devices behind the VMD. Needs to be called 77 * periodically to detect them. 78 * 79 * \return number of hotplug events detected or negative errno in case of errors 80 */ 81 int spdk_vmd_hotplug_monitor(void); 82 83 /** 84 * Removes a given device from the PCI subsystem simulating a hot-remove. If the device is being 85 * actively used by another module, the actual detach might be deferred. 86 * 87 * \param addr Address of a PCI device to remove. 88 * 89 * \return 0 if the device was successfully removed, negative errno otherwise. 90 */ 91 int spdk_vmd_remove_device(const struct spdk_pci_addr *addr); 92 93 /** 94 * Forces a rescan of the devices behind the VMD. If a device was previously removed through 95 * spdk_vmd_remove_device() this will cause it to be reattached. 96 * 97 * \return number of new devices found during scanning or negative errno on failure. 98 */ 99 int spdk_vmd_rescan(void); 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* SPDK_VMD_H */ 106