1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2019 6WIND S.A.
3 * Copyright 2019 Mellanox Technologies, Ltd
10 #include <rte_errno.h>
12 #include "mlx5_common_mp.h"
13 #include "mlx5_common_log.h"
14 #include "mlx5_malloc.h"
17 * Request Memory Region creation to the primary process.
20 * ID of the MP process.
22 * Target virtual address to register.
25 * 0 on success, a negative errno value otherwise and rte_errno is set.
28 mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr)
30 struct rte_mp_msg mp_req;
31 struct rte_mp_msg *mp_res;
32 struct rte_mp_reply mp_rep;
33 struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
34 struct mlx5_mp_param *res;
35 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
38 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
39 mp_init_msg(mp_id, &mp_req, MLX5_MP_REQ_CREATE_MR);
40 req->args.addr = addr;
41 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
43 DRV_LOG(ERR, "port %u request to primary process failed",
47 MLX5_ASSERT(mp_rep.nb_received == 1);
48 mp_res = &mp_rep.msgs[0];
49 res = (struct mlx5_mp_param *)mp_res->param;
53 mlx5_free(mp_rep.msgs);
58 * Request Verbs queue state modification to the primary process.
61 * ID of the MP process.
63 * State modify parameters.
66 * 0 on success, a negative errno value otherwise and rte_errno is set.
69 mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
70 struct mlx5_mp_arg_queue_state_modify *sm)
72 struct rte_mp_msg mp_req;
73 struct rte_mp_msg *mp_res;
74 struct rte_mp_reply mp_rep;
75 struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
76 struct mlx5_mp_param *res;
77 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
80 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
81 mp_init_msg(mp_id, &mp_req, MLX5_MP_REQ_QUEUE_STATE_MODIFY);
82 req->args.state_modify = *sm;
83 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
85 DRV_LOG(ERR, "port %u request to primary process failed",
89 MLX5_ASSERT(mp_rep.nb_received == 1);
90 mp_res = &mp_rep.msgs[0];
91 res = (struct mlx5_mp_param *)mp_res->param;
93 mlx5_free(mp_rep.msgs);
98 * Request Verbs command file descriptor for mmap to the primary process.
101 * ID of the MP process.
104 * fd on success, a negative errno value otherwise and rte_errno is set.
107 mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id)
109 struct rte_mp_msg mp_req;
110 struct rte_mp_msg *mp_res;
111 struct rte_mp_reply mp_rep;
112 struct mlx5_mp_param *res;
113 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
116 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
117 mp_init_msg(mp_id, &mp_req, MLX5_MP_REQ_VERBS_CMD_FD);
118 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
120 DRV_LOG(ERR, "port %u request to primary process failed",
124 MLX5_ASSERT(mp_rep.nb_received == 1);
125 mp_res = &mp_rep.msgs[0];
126 res = (struct mlx5_mp_param *)mp_res->param;
128 rte_errno = -res->result;
130 "port %u failed to get command FD from primary process",
135 MLX5_ASSERT(mp_res->num_fds == 1);
136 ret = mp_res->fds[0];
137 DRV_LOG(DEBUG, "port %u command FD from primary is %d",
138 mp_id->port_id, ret);
140 mlx5_free(mp_rep.msgs);
145 * Initialize by primary process.
148 mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action)
152 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
154 /* primary is allowed to not support IPC */
155 ret = rte_mp_action_register(name, primary_action);
156 if (ret && rte_errno != ENOTSUP)
162 * Un-initialize by primary process.
165 mlx5_mp_uninit_primary(const char *name)
167 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
168 rte_mp_action_unregister(name);
172 * Initialize by secondary process.
175 mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action)
177 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
178 return rte_mp_action_register(name, secondary_action);
182 * Un-initialize by secondary process.
185 mlx5_mp_uninit_secondary(const char *name)
187 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
188 rte_mp_action_unregister(name);