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_utils.h"
16 * Request Memory Region creation to the primary process.
19 * ID of the MP process.
21 * Target virtual address to register.
24 * 0 on success, a negative errno value otherwise and rte_errno is set.
27 mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr)
29 struct rte_mp_msg mp_req;
30 struct rte_mp_msg *mp_res;
31 struct rte_mp_reply mp_rep;
32 struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
33 struct mlx5_mp_param *res;
34 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
37 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
38 mp_init_msg(mp_id, &mp_req, MLX5_MP_REQ_CREATE_MR);
39 req->args.addr = addr;
40 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
42 DRV_LOG(ERR, "port %u request to primary process failed",
46 MLX5_ASSERT(mp_rep.nb_received == 1);
47 mp_res = &mp_rep.msgs[0];
48 res = (struct mlx5_mp_param *)mp_res->param;
57 * Request Verbs queue state modification to the primary process.
60 * ID of the MP process.
62 * State modify parameters.
65 * 0 on success, a negative errno value otherwise and rte_errno is set.
68 mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
69 struct mlx5_mp_arg_queue_state_modify *sm)
71 struct rte_mp_msg mp_req;
72 struct rte_mp_msg *mp_res;
73 struct rte_mp_reply mp_rep;
74 struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
75 struct mlx5_mp_param *res;
76 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
79 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
80 mp_init_msg(mp_id, &mp_req, MLX5_MP_REQ_QUEUE_STATE_MODIFY);
81 req->args.state_modify = *sm;
82 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
84 DRV_LOG(ERR, "port %u request to primary process failed",
88 MLX5_ASSERT(mp_rep.nb_received == 1);
89 mp_res = &mp_rep.msgs[0];
90 res = (struct mlx5_mp_param *)mp_res->param;
97 * Request Verbs command file descriptor for mmap to the primary process.
100 * ID of the MP process.
103 * fd on success, a negative errno value otherwise and rte_errno is set.
106 mlx5_mp_req_verbs_cmd_fd(struct mlx5_mp_id *mp_id)
108 struct rte_mp_msg mp_req;
109 struct rte_mp_msg *mp_res;
110 struct rte_mp_reply mp_rep;
111 struct mlx5_mp_param *res;
112 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
115 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
116 mp_init_msg(mp_id, &mp_req, MLX5_MP_REQ_VERBS_CMD_FD);
117 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
119 DRV_LOG(ERR, "port %u request to primary process failed",
123 MLX5_ASSERT(mp_rep.nb_received == 1);
124 mp_res = &mp_rep.msgs[0];
125 res = (struct mlx5_mp_param *)mp_res->param;
127 rte_errno = -res->result;
129 "port %u failed to get command FD from primary process",
134 MLX5_ASSERT(mp_res->num_fds == 1);
135 ret = mp_res->fds[0];
136 DRV_LOG(DEBUG, "port %u command FD from primary is %d",
137 mp_id->port_id, ret);
144 * Initialize by primary process.
147 mlx5_mp_init_primary(const char *name, const rte_mp_t primary_action)
151 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
153 /* primary is allowed to not support IPC */
154 ret = rte_mp_action_register(name, primary_action);
155 if (ret && rte_errno != ENOTSUP)
161 * Un-initialize by primary process.
164 mlx5_mp_uninit_primary(const char *name)
166 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
167 rte_mp_action_unregister(name);
171 * Initialize by secondary process.
174 mlx5_mp_init_secondary(const char *name, const rte_mp_t secondary_action)
176 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
177 return rte_mp_action_register(name, secondary_action);
181 * Un-initialize by secondary process.
184 mlx5_mp_uninit_secondary(const char *name)
186 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
187 rte_mp_action_unregister(name);