NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
devemu_pci_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef DEVEMU_PCI_COMMON_H_
27 #define DEVEMU_PCI_COMMON_H_
28 
29 #include <stdbool.h>
30 
31 #include <doca_error.h>
32 #include <doca_argp.h>
33 #include <doca_log.h>
34 #include <doca_devemu_pci_type.h>
35 #include <doca_devemu_pci.h>
36 #include <doca_dpa.h>
37 
38 #include "devemu_pci_type_config.h"
39 
40 #define SLEEP_IN_MICROS (10) /* Sample the task every 10 microseconds */
41 #define SLEEP_IN_NANOS (SLEEP_IN_MICROS * 1000)
42 
43 /* Function to check if a given device supports PCI emulation */
44 typedef doca_error_t (*emulation_supported_cb_t)(const struct doca_devinfo *,
45  const struct doca_devemu_pci_type *pci_type,
46  uint8_t *is_supported);
47 
49  struct doca_pe *pe;
50  struct doca_dev *dev;
51  struct doca_devemu_pci_type *pci_type;
52  struct doca_dev_rep *rep;
53  struct doca_devemu_pci_dev *pci_dev;
54  struct doca_ctx *ctx;
57  struct doca_dpa *dpa;
58  struct doca_dpa_thread *dpa_thread;
59  struct doca_devemu_pci_db_completion *db_comp;
61  uint16_t db_region_idx;
62  uint32_t db_id;
63  struct {
64  struct doca_devemu_pci_msix *msix;
66  struct doca_devemu_pci_db *db;
70 };
71 
72 /*
73  * Parse pci address taken from command line
74  *
75  * @addr [in]: Input parameter received from command line
76  * @parsed_addr [out]: Used to store parsed address
77  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
78  */
79 doca_error_t parse_pci_address(const char *addr, char *parsed_addr);
80 
81 /*
82  * Register PCI address command line parameter
83  *
84  * @pci_callback [in]: Callback called for parsing the PCI address command line param
85  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
86  */
88 
89 /*
90  * Parse VUID taken from command line
91  *
92  * @vuid [in]: Input parameter received from command line
93  * @parsed_vuid [out]: Used to store parsed VUID
94  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
95  */
96 doca_error_t parse_vuid(const char *vuid, char *parsed_vuid);
97 
98 /*
99  * Register VUID command line parameter
100  *
101  * @description [in]: Description displayed in help message
102  * @vuid_callback [in]: Callback called for parsing the VUID command line param
103  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
104  */
106 
107 /*
108  * Open a DOCA device according to a given PCI address
109  * Picks device that has given PCI address and supports hotplug of the PCI type
110  *
111  * @pci_address [in]: PCI address
112  * @pci_type [in]: The emulated PCI type
113  * @has_support [in]: Method to check if device hsupports emulation
114  * @dev [out]: pointer to doca_dev struct, NULL if not found
115  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
116  */
117 doca_error_t find_supported_device(const char *pci_address,
118  const struct doca_devemu_pci_type *pci_type,
119  emulation_supported_cb_t has_support,
120  struct doca_dev **dev);
121 
122 /*
123  * Open an emulated PCI device representor according to type and given VUID
124  *
125  * @pci_type [in]: The emulated PCI type
126  * @vuid [in]: The VUID of the emulated device
127  * @rep [out]: pointer to doca_dev_rep struct, NULL if not found
128  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
129  */
130 doca_error_t find_emulated_device(struct doca_devemu_pci_type *pci_type, const char *vuid, struct doca_dev_rep **rep);
131 
132 /*
133  * Sets the PCI configurations of the type and then starts it
134  * Once device is hotplugged the configurations will be visible to the Host as part of the
135  * PCI configuration space of that device
136  *
137  * @pci_type [in]: The emulated PCI type
138  * @dev [in]: The device that manages the PCI type
139  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
140  */
141 doca_error_t configure_and_start_pci_type(struct doca_devemu_pci_type *pci_type, struct doca_dev *dev);
142 
143 /*
144  * Cleanup resources of the sample
145  *
146  * @resources [in]: The resources of the sample
147  * @destroy_rep [in]: Whether to destroy the representor or only close it
148  */
149 void devemu_resources_cleanup(struct devemu_resources *resources, bool destroy_rep);
150 
151 /*
152  * Convert enum doca_devemu_pci_hotplug_state to string
153  *
154  * @hotplug_state [in]: The hotplug state to convert
155  * @return: String representation of the hotplug state
156  */
157 const char *hotplug_state_to_string(enum doca_devemu_pci_hotplug_state hotplug_state);
158 
159 /*
160  * Initialize a DPA context for given DPA application
161  *
162  * @resources [in]: The resources of the sample
163  * @dpa_app [in]: The DPA application
164  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
165  */
166 doca_error_t init_dpa(struct devemu_resources *resources, struct doca_dpa_app *dpa_app);
167 
168 #endif // DEVEMU_PCI_COMMON_H_
static doca_error_t vuid_callback(void *param, void *config)
doca_error_t configure_and_start_pci_type(struct doca_devemu_pci_type *pci_type, struct doca_dev *dev)
doca_error_t init_dpa(struct devemu_resources *resources, struct doca_dpa_app *dpa_app)
doca_error_t parse_pci_address(const char *addr, char *parsed_addr)
void devemu_resources_cleanup(struct devemu_resources *resources, bool destroy_rep)
const char * hotplug_state_to_string(enum doca_devemu_pci_hotplug_state hotplug_state)
doca_error_t register_vuid_param(const char *description, doca_argp_param_cb_t vuid_callback)
doca_error_t parse_vuid(const char *vuid, char *parsed_vuid)
doca_error_t find_emulated_device(struct doca_devemu_pci_type *pci_type, const char *vuid, struct doca_dev_rep **rep)
doca_error_t register_pci_address_param(doca_argp_param_cb_t pci_callback)
doca_error_t find_supported_device(const char *pci_address, const struct doca_devemu_pci_type *pci_type, emulation_supported_cb_t has_support, struct doca_dev **dev)
doca_error_t(* emulation_supported_cb_t)(const struct doca_devinfo *, const struct doca_devemu_pci_type *pci_type, uint8_t *is_supported)
static doca_error_t pci_callback(void *param, void *config)
uintptr_t addr
struct rdma_resources resources
doca_error_t(* doca_argp_param_cb_t)(void *, void *)
Flag callback function type.
Definition: doca_argp.h:37
uint64_t doca_dpa_dev_devemu_pci_db_completion_t
DPA handle for emulated PCI device doorbell completion context.
uint64_t doca_dpa_dev_devemu_pci_db_t
DPA handle for emulated PCI device doorbell.
doca_devemu_pci_hotplug_state
DOCA devemu pci hotplug state.
uint64_t doca_dpa_dev_devemu_pci_msix_t
DPA handle for emulated PCI device MSI-X.
enum doca_error doca_error_t
DOCA API return codes.
type description
struct doca_devemu_pci_msix * msix
struct doca_devemu_pci_dev * pci_dev
struct doca_dpa_thread * dpa_thread
struct doca_devemu_pci_db * db
struct doca_dev * dev
doca_dpa_dev_devemu_pci_db_completion_t db_comp_handle
struct doca_dev_rep * rep
doca_error_t error
struct doca_pe * pe
struct doca_devemu_pci_type * pci_type
doca_dpa_dev_devemu_pci_db_t db_handle
doca_dpa_dev_devemu_pci_msix_t msix_handle
struct doca_devemu_pci_db_completion * db_comp
struct doca_dpa * dpa
enum doca_devemu_pci_hotplug_state hotplug_state
struct doca_ctx * ctx
struct devemu_resources::@164 data_path