29 #include <netinet/in.h>
31 #include <sys/epoll.h>
48 #define CC_MAX_QUEUE_SIZE 10
49 #define SLEEP_IN_NANOS (10 * 1000)
50 #define STATUS_SUCCESS true
51 #define STATUS_FAILURE false
69 DOCA_LOG_ERR(
"Failed to retrieve maximum buffer size allowed from DOCA DMA device: %s",
72 DOCA_LOG_DBG(
"DOCA DMA device supports maximum buffer size of %" PRIu64
" bytes", *max_buf_size);
89 fp = fopen(file_path,
"r");
95 if (fseek(fp, 0, SEEK_END) != 0) {
127 if (access(
cfg->file_path, F_OK | R_OK) == 0) {
128 cfg->is_file_found_locally =
true;
145 const char *dev_pci_addr = (
char *)param;
148 DOCA_LOG_ERR(
"Entered device PCI address exceeding the maximum size of %d",
191 const char *rep_pci_addr = (
char *)param;
195 DOCA_LOG_ERR(
"Entered device representor PCI address exceeding the maximum size of %d",
217 fp = fopen(
cfg->file_path,
"w");
223 if (fwrite(buffer, 1,
cfg->file_size, fp) !=
cfg->file_size) {
224 DOCA_LOG_ERR(
"Failed to write full content into the output file");
245 fp = fopen(
cfg->file_path,
"r");
252 if (fread(buffer, 1,
cfg->file_size, fp) !=
cfg->file_size) {
273 uint32_t access_flags,
284 *buffer = (
char *)malloc(buffer_len);
285 if (*buffer ==
NULL) {
286 DOCA_LOG_ERR(
"Failed to allocate memory for source buffer");
322 size_t bytes_to_copy,
324 struct doca_buf *local_doca_buf,
325 struct doca_buf *remote_doca_buf,
326 size_t *num_remaining_tasks)
329 struct doca_dma_task_memcpy *dma_task;
330 struct doca_task *task;
333 struct doca_buf *src_buf;
334 struct doca_buf *dst_buf;
335 struct timespec ts = {
343 if (
cfg->is_file_found_locally) {
344 src_buf = local_doca_buf;
345 dst_buf = remote_doca_buf;
347 src_buf = remote_doca_buf;
348 dst_buf = local_doca_buf;
364 task_user_data.
ptr = &task_result;
382 while (*num_remaining_tasks > 0) {
397 if (!
cfg->is_file_found_locally) {
423 struct doca_argp_param *file_path_param, *dev_pci_addr_param, *rep_pci_addr_param;
434 "Full path to file to be copied/created after a successful DMA copy");
471 "DOCA Comch device representor PCI address (needed only on DPU)");
519 size_t *num_remaining_tasks = (
size_t *)ctx_user_data.
ptr;
524 --*num_remaining_tasks;
540 size_t *num_remaining_tasks = (
size_t *)ctx_user_data.
ptr;
545 --*num_remaining_tasks;
591 uint32_t max_bufs = 2;
663 static void send_status_msg(
struct doca_comch_connection *comch_connection,
bool status)
685 struct doca_comch_connection *comch_connection,
689 char export_msg[
cfg->max_comch_buffer];
691 const void *export_desc;
695 if (!
cfg->is_file_found_locally) {
721 if (exp_msg_len >
cfg->max_comch_buffer) {
722 DOCA_LOG_ERR(
"Export message exceeds max length of comch. Message len: %lu, Max len: %u",
724 cfg->max_comch_buffer);
736 uint8_t *recv_buffer,
738 struct doca_comch_connection *comch_connection)
754 DOCA_LOG_ERR(
"Received a message that is too small. Length: %u", msg_len);
774 DOCA_LOG_ERR(
"Direction message has bad length. Length: %u, expected: %lu",
794 DOCA_LOG_ERR(
"Status message has bad length. Length: %u, expected: %lu",
829 DOCA_LOG_INFO(
"File was found locally, it will be DMA copied to the DPU");
833 DOCA_LOG_INFO(
"File was not found locally, it will be DMA copied from the DPU");
843 struct timespec ts = {
912 DOCA_LOG_INFO(
"Final status message was successfully received");
946 struct doca_comch_connection *comch_connection,
954 DOCA_LOG_ERR(
"Error - File was found on both Host and DPU");
957 }
else if (!
cfg->is_file_found_locally) {
959 DOCA_LOG_ERR(
"Error - File was not found on both Host and DPU");
966 if (
cfg->file_size >
cfg->max_dma_buf_size) {
967 DOCA_LOG_ERR(
"DMA device maximum allowed file size in bytes is %" PRIu64
968 ", received file size is %" PRIu64
" bytes",
969 cfg->max_dma_buf_size,
975 if (
cfg->is_file_found_locally) {
976 DOCA_LOG_INFO(
"File was found locally, it will be DMA copied to the Host");
980 DOCA_LOG_INFO(
"File was not found locally, it will be DMA copied from the Host");
1005 cfg->exported_mmap = malloc(desc_len);
1006 if (
cfg->exported_mmap ==
NULL) {
1007 DOCA_LOG_ERR(
"Failed to allocate export descriptor memory");
1012 cfg->exported_mmap_len = desc_len;
1019 uint8_t *recv_buffer,
1021 struct doca_comch_connection *comch_connection)
1037 DOCA_LOG_ERR(
"Received a message that is too small. Length: %u", msg_len);
1056 DOCA_LOG_ERR(
"Direction message has bad length. Length: %u, expected: %lu",
1075 DOCA_LOG_ERR(
"Direction message has bad length. Length: %u, expected at least: %lu",
1095 DOCA_LOG_ERR(
"Status message has bad length. Length: %u, expected: %lu",
1123 struct doca_buf *remote_doca_buf =
NULL;
1124 struct doca_buf *local_doca_buf =
NULL;
1125 struct doca_mmap *remote_mmap =
NULL;
1128 size_t num_remaining_tasks = 1;
1130 struct timespec ts = {
1147 ctx_user_data.
ptr = &num_remaining_tasks;
1158 nanosleep(&ts, &ts);
1197 goto destroy_remote_mmap;
1209 goto destroy_remote_buf;
1217 goto destroy_local_buf;
1228 &num_remaining_tasks);
1231 goto destroy_local_buf;
1248 destroy_remote_mmap:
void * comch_utils_get_user_data(struct doca_comch_connection *connection)
doca_error_t comch_utils_progress_connection(struct doca_comch_connection *connection)
struct doca_comch_connection * comch_util_get_connection(struct comch_cfg *comch_cfg)
doca_error_t comch_utils_send(struct doca_comch_connection *connection, const void *msg, uint32_t len)
uint32_t comch_utils_get_max_buffer_size(struct comch_cfg *comch_cfg)
doca_error_t request_stop_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
doca_error_t destroy_core_objects(struct program_core_objects *state)
doca_error_t create_core_objects(struct program_core_objects *state, uint32_t max_bufs)
doca_error_t open_doca_device_with_capabilities(tasks_check func, struct doca_dev **retval)
doca_error_t destroy_dma_resources(struct dma_resources *resources)
static doca_error_t file_path_callback(void *param, void *config)
doca_error_t open_dma_device(struct doca_dev **dev)
static doca_error_t host_process_dma_direction_and_size(struct dma_copy_cfg *cfg, struct doca_comch_connection *comch_connection, struct comch_msg_dma_direction *dir_msg)
static doca_error_t send_file_direction_request(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
static doca_error_t dpu_process_export_descriptor(struct dma_copy_cfg *cfg, struct comch_msg_dma_export_discriptor *des_msg)
static void send_status_msg(struct doca_comch_connection *comch_connection, bool status)
static doca_error_t args_validation_callback(void *config)
static doca_error_t dpu_process_dma_direction_and_size(struct dma_copy_cfg *cfg, struct doca_comch_connection *comch_connection, struct comch_msg_dma_direction *dir_msg)
static doca_error_t memory_alloc_and_populate(struct doca_mmap *mmap, size_t buffer_len, uint32_t access_flags, char **buffer)
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)
static doca_error_t dpu_submit_dma_task(struct dma_copy_cfg *cfg, struct dma_copy_resources *resources, size_t bytes_to_copy, char *buffer, struct doca_buf *local_doca_buf, struct doca_buf *remote_doca_buf, size_t *num_remaining_tasks)
static doca_error_t rep_pci_addr_callback(void *param, void *config)
static doca_error_t fill_buffer_with_file_content(struct dma_copy_cfg *cfg, char *buffer)
DOCA_LOG_REGISTER(DMA_COPY_CORE)
static void dma_memcpy_completed_callback(struct doca_dma_task_memcpy *dma_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t get_dma_max_buf_size(struct dma_copy_resources *resources, uint64_t *max_buf_size)
static void dma_memcpy_error_callback(struct doca_dma_task_memcpy *dma_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t allocate_dma_copy_resources(struct dma_copy_resources *resources)
doca_error_t register_dma_copy_params(void)
static doca_error_t validate_file_size(const char *file_path, uint64_t *file_size)
static doca_error_t save_buffer_into_a_file(struct dma_copy_cfg *cfg, const char *buffer)
doca_error_t dpu_start_dma_copy(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
static doca_error_t check_dev_dma_capable(struct doca_devinfo *devinfo)
static doca_error_t dev_pci_addr_callback(void *param, void *config)
static doca_error_t destroy_dma_copy_resources(struct dma_copy_resources *resources)
doca_error_t host_start_dma_copy(struct dma_copy_cfg *dma_cfg, struct comch_cfg *comch_cfg)
@ COMCH_MSG_EXPORT_DESCRIPTOR
struct rdma_resources resources
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_validation_callback(doca_argp_validation_cb_t callback)
Register program validation callback function.
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_mandatory(struct doca_argp_param *param)
Mark the program param as mandatory.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_version_callback(doca_argp_param_cb_t callback)
Register an alternative version callback.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
static doca_error_t doca_buf_inventory_buf_get_by_addr(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *addr, size_t len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by addr & len argume...
DOCA_STABLE doca_error_t doca_buf_dec_refcount(struct doca_buf *buf, uint16_t *refcount)
Decrease the object reference count by 1, if 0 reached, return the element back to the inventory.
DOCA_STABLE doca_error_t doca_buf_get_data(const struct doca_buf *buf, void **data)
Get the buffer's data.
DOCA_STABLE doca_error_t doca_buf_set_data(struct doca_buf *buf, void *data, size_t data_len)
DOCA_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
DOCA_STABLE doca_error_t doca_ctx_set_user_data(struct doca_ctx *ctx, union doca_data user_data)
set user data to context
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
DOCA_STABLE struct doca_task * doca_dma_task_memcpy_as_task(struct doca_dma_task_memcpy *task)
This method converts a memcpy task to doca_task.
DOCA_STABLE doca_error_t doca_dma_task_memcpy_alloc_init(struct doca_dma *dma, const struct doca_buf *src, struct doca_buf *dst, union doca_data user_data, struct doca_dma_task_memcpy **task)
This method allocates and initializes a DMA memcpy task.
DOCA_STABLE struct doca_ctx * doca_dma_as_ctx(struct doca_dma *dma)
DOCA_STABLE doca_error_t doca_dma_task_memcpy_set_conf(struct doca_dma *dma, doca_dma_task_memcpy_completion_cb_t task_completion_cb, doca_dma_task_memcpy_completion_cb_t task_error_cb, uint32_t num_memcpy_tasks)
This method sets the DMA memcpy tasks configuration.
DOCA_STABLE doca_error_t doca_dma_cap_task_memcpy_is_supported(const struct doca_devinfo *devinfo)
DOCA_STABLE doca_error_t doca_dma_cap_task_memcpy_get_max_buf_size(const struct doca_devinfo *devinfo, uint64_t *buf_size)
DOCA_STABLE doca_error_t doca_dma_create(struct doca_dev *dev, struct doca_dma **dma)
DOCA_STABLE doca_error_t doca_dma_destroy(struct doca_dma *dma)
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_destroy(struct doca_mmap *mmap)
Destroy DOCA Memory Map structure.
DOCA_STABLE doca_error_t doca_mmap_create(struct doca_mmap **mmap)
Allocates zero size memory map object with default/unset attributes.
DOCA_STABLE doca_error_t doca_mmap_create_from_export(const union doca_data *user_data, const void *export_desc, size_t export_desc_len, struct doca_dev *dev, struct doca_mmap **mmap)
Creates a memory map object representing memory ranges in remote system memory space.
DOCA_STABLE doca_error_t doca_mmap_set_permissions(struct doca_mmap *mmap, uint32_t access_mask)
Set access flags of the registered memory.
DOCA_STABLE doca_error_t doca_mmap_export_pci(struct doca_mmap *mmap, const struct doca_dev *dev, const void **export_desc, size_t *export_desc_len)
Compose memory map representation for later import with doca_mmap_create_from_export() for one of the...
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_add_dev(struct doca_mmap *mmap, struct doca_dev *dev)
Register DOCA memory map on a given device.
DOCA_STABLE doca_error_t doca_task_get_status(const struct doca_task *task)
Get task status.
DOCA_STABLE doca_error_t doca_pe_connect_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
This method connects a context to a progress engine.
DOCA_STABLE doca_error_t doca_task_submit(struct doca_task *task)
Submit a task to a progress engine.
DOCA_STABLE uint8_t doca_pe_progress(struct doca_pe *pe)
Run the progress engine.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
@ DOCA_ACCESS_FLAG_LOCAL_READ_WRITE
@ DOCA_ACCESS_FLAG_LOCAL_READ_ONLY
@ DOCA_ACCESS_FLAG_PCI_READ_WRITE
@ DOCA_ACCESS_FLAG_PCI_READ_ONLY
const struct ip_frag_config * cfg
uint64_t ntohq(uint64_t value)
__UINTPTR_TYPE__ uintptr_t
enum dma_comch_state comch_state
uint64_t max_dma_buf_size
char file_path[MAX_ARG_SIZE]
uint32_t max_comch_buffer
bool is_file_found_locally
struct doca_mmap * file_mmap
struct doca_mmap * src_mmap
struct doca_buf_inventory * buf_inv
Convenience type for representing opaque data.
size_t strlcpy(char *dst, const char *src, size_t size)
noreturn doca_error_t sdk_version_callback(void *param, void *doca_config)