NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dma_copy_core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 DMA_COPY_CORE_H_
27 #define DMA_COPY_CORE_H_
28 
29 #include <stdbool.h>
30 
31 #include <doca_argp.h>
32 #include <doca_dev.h>
33 #include <doca_error.h>
34 #include <doca_log.h>
35 #include <doca_pe.h>
36 
37 #include "comch_utils.h"
38 
39 #define MAX_ARG_SIZE 128 /* PCI address and file path maximum length */
40 #define SERVER_NAME "dma copy server" /* Comm Channel service name */
41 #define NUM_DMA_TASKS (1) /* DMA tasks number */
42 
44  DMA_COPY_MODE_HOST, /* Run endpoint in Host */
45  DMA_COPY_MODE_DPU /* Run endpoint in DPU */
46 };
47 
49  COMCH_MSG_DIRECTION = 1, /* Message type to negotiate file direction */
50  COMCH_MSG_EXPORT_DESCRIPTOR = 2, /* Message type to export dma descriptor information */
51  COMCH_MSG_STATUS = 3, /* Generic success/fail message type */
52 };
53 
55  enum comch_msg_type type; /* COMCH_MSG_DIRECTION */
56  bool file_in_host; /* Indicate where the source file is located */
57  uint64_t file_size; /* File size in bytes */
58 };
59 
61  enum comch_msg_type type; /* COMCH_MSG_EXPORT_DESCRIPTOR */
62  uint64_t host_addr; /* Address of file on host side */
63  size_t export_desc_len; /* Length of the exported mmap */
64  uint8_t exported_mmap[]; /* Variable sized array containing exported mmap */
65 };
66 
68  enum comch_msg_type type; /* COMCH_MSG_STATUS */
69  bool is_success; /* Indicate success or failure for last message sent */
70 };
71 
72 struct comch_msg {
73  enum comch_msg_type type; /* Indicator of message type */
74  union {
75  struct comch_msg_dma_direction dir_msg; /* COMCH_MSG_DIRECTION type*/
76  struct comch_msg_dma_export_discriptor exp_msg; /* COMCH_MSG_EXPORT_DESCRIPTOR type */
77  struct comch_msg_dma_status status_msg; /* COMCH_MSG_STATUS type */
78  };
79 };
80 
82  COMCH_NEGOTIATING, /* DMA metadata is being negotiated */
83  COMCH_COMPLETE, /* DMA metadata successfully passed */
84  COMCH_ERROR, /* An error was detected DMA metadata negotiation */
85 };
86 
87 struct dma_copy_cfg {
88  enum dma_copy_mode mode; /* Node running mode {host, dpu} */
89  char file_path[MAX_ARG_SIZE]; /* File path to copy from (host) or path the save DMA result (dpu) */
90  char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Comm Channel DOCA device PCI address */
91  char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]; /* Comm Channel DOCA device representor PCI address */
92  bool is_file_found_locally; /* Indicate DMA copy direction */
93  uint64_t file_size; /* File size in bytes */
94  char *file_buffer; /* Buffer to store field to send or file to receive */
95  struct doca_mmap *file_mmap; /* Mmap associated with the file buffer */
96  struct doca_dev *dev; /* Doca device used for DMA */
97  uint64_t max_dma_buf_size; /* Max size DMA supported */
98 
99  /* DPU side only field */
100  uint8_t *exported_mmap; /* Exported mmap sent from host to DPU */
101  size_t exported_mmap_len; /* Length of exported mmap */
102  uint8_t *host_addr; /* Host address of file to be used with exported mmap */
103 
104  /* Comch connection info */
105  uint32_t max_comch_buffer; /* Max buffer size the comch is configure for */
106  enum dma_comch_state comch_state; /* Current state of DMA metadata negotiation on the comch */
107 };
108 
110  struct program_core_objects *state; /* DOCA core objects */
111  struct doca_dma *dma_ctx; /* DOCA DMA context */
112 };
113 
114 /*
115  * Register application arguments
116  *
117  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
118  */
120 
121 /*
122  * Open DOCA device for DMA operation
123  *
124  * @dev [in]: DOCA DMA capable device to open
125  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
126  */
127 doca_error_t open_dma_device(struct doca_dev **dev);
128 
129 /*
130  * Start DMA operation on the Host
131  *
132  * @dma_cfg [in]: App configuration structure
133  * @comch_cfg [in]: Doca comch initialized objects
134  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
135  */
137 /*
138  * Start DMA operation on the DPU
139  *
140  * @dma_cfg [in]: App configuration structure
141  * @comch_cfg [in]: Doca comch initialized objects
142  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
143  */
145 
146 /*
147  * Callback event for client messages
148  *
149  * @event [in]: message receive event
150  * @recv_buffer [in]: array of bytes containing the message data
151  * @msg_len [in]: number of bytes in the recv_buffer
152  * @comch_connection [in]: comm channel connection over which the event occurred
153  */
154 void host_recv_event_cb(struct doca_comch_event_msg_recv *event,
155  uint8_t *recv_buffer,
156  uint32_t msg_len,
157  struct doca_comch_connection *comch_connection);
158 
159 /*
160  * Callback event for server messages
161  *
162  * @event [in]: message receive event
163  * @recv_buffer [in]: array of bytes containing the message data
164  * @msg_len [in]: number of bytes in the recv_buffer
165  * @comch_connection [in]: comm channel connection over which the event occurred
166  */
167 void dpu_recv_event_cb(struct doca_comch_event_msg_recv *event,
168  uint8_t *recv_buffer,
169  uint32_t msg_len,
170  struct doca_comch_connection *comch_connection);
171 
172 #endif /* DMA_COPY_CORE_H_ */
doca_error_t open_dma_device(struct doca_dev **dev)
dma_comch_state
Definition: dma_copy_core.h:81
@ COMCH_ERROR
Definition: dma_copy_core.h:84
@ COMCH_COMPLETE
Definition: dma_copy_core.h:83
@ COMCH_NEGOTIATING
Definition: dma_copy_core.h:82
void host_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void dpu_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
#define MAX_ARG_SIZE
Definition: dma_copy_core.h:39
doca_error_t register_dma_copy_params(void)
doca_error_t dpu_start_dma_copy(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
doca_error_t host_start_dma_copy(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
comch_msg_type
Definition: dma_copy_core.h:48
@ COMCH_MSG_EXPORT_DESCRIPTOR
Definition: dma_copy_core.h:50
@ COMCH_MSG_DIRECTION
Definition: dma_copy_core.h:49
@ COMCH_MSG_STATUS
Definition: dma_copy_core.h:51
dma_copy_mode
Definition: dma_copy_core.h:43
@ DMA_COPY_MODE_HOST
Definition: dma_copy_core.h:44
@ DMA_COPY_MODE_DPU
Definition: dma_copy_core.h:45
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:665
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
enum doca_error doca_error_t
DOCA API return codes.
enum comch_msg_type type
Definition: dma_copy_core.h:55
enum comch_msg_type type
Definition: dma_copy_core.h:68
struct comch_msg_dma_direction dir_msg
Definition: dma_copy_core.h:75
struct comch_msg_dma_status status_msg
Definition: dma_copy_core.h:77
struct comch_msg_dma_export_discriptor exp_msg
Definition: dma_copy_core.h:76
enum comch_msg_type type
Definition: dma_copy_core.h:73
uint8_t * exported_mmap
uint8_t * host_addr
char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]
Definition: dma_copy_core.h:91
char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: dma_copy_core.h:90
uint64_t file_size
Definition: dma_copy_core.h:93
struct doca_dev * dev
Definition: dma_copy_core.h:96
enum dma_comch_state comch_state
uint64_t max_dma_buf_size
Definition: dma_copy_core.h:97
enum dma_copy_mode mode
Definition: dma_copy_core.h:88
char file_path[MAX_ARG_SIZE]
Definition: dma_copy_core.h:89
uint32_t max_comch_buffer
size_t exported_mmap_len
char * file_buffer
Definition: dma_copy_core.h:94
bool is_file_found_locally
Definition: dma_copy_core.h:92
struct doca_mmap * file_mmap
Definition: dma_copy_core.h:95
struct program_core_objects * state
struct doca_dma * dma_ctx