xref: /spdk/test/external_code/nvme/nvme.h (revision a5f87f39127c7e0da8d9c4fcd042a27e350be84e)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2021 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef EXTERNAL_NVME_H
7 #define EXTERNAL_NVME_H
8 
9 #include "spdk/env.h"
10 #include "spdk/nvme_spec.h"
11 
12 struct nvme_ctrlr;
13 
14 /**
15  * Callback for nvme_probe() to report a device that has been attached to
16  * the userspace NVMe driver.
17  *
18  * \param cb_ctx Opaque value passed to nvme_attach_cb().
19  * \param addr The PCI address of the NVMe controller.
20  * \param ctrlr Opaque handle to NVMe controller.
21  */
22 typedef void (*nvme_attach_cb)(void *cb_ctx, const struct spdk_pci_addr *addr,
23 			       struct nvme_ctrlr *ctrlr);
24 
25 /**
26  * Enumerate PCIe bus and attach all NVMe devices found to the driver.
27  *
28  * This function is not thread safe and should only be called from one thread at
29  * a time while no other threads are actively using any NVMe devices.
30  *
31  * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of
32  * the callbacks.
33  * \param attach_cb will be called for each NVMe device found
34  *
35  * \return 0 on success, negative errno on failure.
36  */
37 int nvme_probe(nvme_attach_cb attach_cb, void *ctx);
38 
39 /**
40  * Connect the NVMe driver to the device located at the given transport ID.
41  *
42  * This function is not thread safe and should only be called from one thread at
43  * a time while no other threads are actively using this NVMe device.
44  *
45  * \param addr The PCI address of the NVMe controller to connect.
46  *
47  * \return pointer to the connected NVMe controller or NULL if there is any failure.
48  */
49 struct nvme_ctrlr *nvme_connect(struct spdk_pci_addr *addr);
50 
51 /**
52  * Detach specified device returned by nvme_probe()'s attach_cb. After returning
53  * the nvme_ctrlr handle is no longer valid.
54  *
55  * This function should be called from a single thread while no other threads
56  * are actively using the NVMe device.
57  *
58  * \param ctrlr Opaque handle to NVMe controller.
59  */
60 void nvme_detach(struct nvme_ctrlr *ctrlr);
61 
62 /**
63  * Get the identify controller data as defined by the NVMe specification.
64  *
65  * This function is thread safe and can be called at any point while the controller
66  * is attached to the SPDK NVMe driver.
67  *
68  * \param ctrlr Opaque handle to NVMe controller.
69  *
70  * \return pointer to the identify controller data.
71  */
72 const struct spdk_nvme_ctrlr_data *nvme_ctrlr_get_data(struct nvme_ctrlr *ctrlr);
73 
74 #endif /* EXTERNAL_NVME_H */
75