1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2019 6WIND S.A.
3 * Copyright 2019 Mellanox Technologies, Ltd
11 #include <rte_ethdev_driver.h>
12 #include <rte_string_fns.h>
15 #include "mlx4_rxtx.h"
16 #include "mlx4_utils.h"
19 * Initialize IPC message.
22 * Pointer to Ethernet structure.
24 * Pointer to message to fill in.
29 mp_init_msg(struct rte_eth_dev *dev, struct rte_mp_msg *msg,
30 enum mlx4_mp_req_type type)
32 struct mlx4_mp_param *param = (struct mlx4_mp_param *)msg->param;
34 memset(msg, 0, sizeof(*msg));
35 strlcpy(msg->name, MLX4_MP_NAME, sizeof(msg->name));
36 msg->len_param = sizeof(*param);
38 param->port_id = dev->data->port_id;
42 * IPC message handler of primary process.
45 * Pointer to Ethernet structure.
47 * Pointer to the peer socket path.
50 * 0 on success, negative errno value otherwise and rte_errno is set.
53 mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
55 struct rte_mp_msg mp_res;
56 struct mlx4_mp_param *res = (struct mlx4_mp_param *)mp_res.param;
57 const struct mlx4_mp_param *param =
58 (const struct mlx4_mp_param *)mp_msg->param;
59 struct rte_eth_dev *dev;
60 struct mlx4_priv *priv;
63 assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
64 if (!rte_eth_dev_is_valid_port(param->port_id)) {
66 ERROR("port %u invalid port ID", param->port_id);
69 dev = &rte_eth_devices[param->port_id];
70 priv = dev->data->dev_private;
71 switch (param->type) {
72 case MLX4_MP_REQ_VERBS_CMD_FD:
73 mp_init_msg(dev, &mp_res, param->type);
75 mp_res.fds[0] = priv->ctx->cmd_fd;
77 ret = rte_mp_reply(&mp_res, peer);
81 ERROR("port %u invalid mp request type", dev->data->port_id);
88 * IPC message handler of a secondary process.
91 * Pointer to Ethernet structure.
93 * Pointer to the peer socket path.
96 * 0 on success, a negative errno value otherwise and rte_errno is set.
99 mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
101 struct rte_mp_msg mp_res;
102 struct mlx4_mp_param *res = (struct mlx4_mp_param *)mp_res.param;
103 const struct mlx4_mp_param *param =
104 (const struct mlx4_mp_param *)mp_msg->param;
105 struct rte_eth_dev *dev;
108 assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
109 if (!rte_eth_dev_is_valid_port(param->port_id)) {
111 ERROR("port %u invalid port ID", param->port_id);
114 dev = &rte_eth_devices[param->port_id];
115 switch (param->type) {
116 case MLX4_MP_REQ_START_RXTX:
117 INFO("port %u starting datapath", dev->data->port_id);
119 dev->tx_pkt_burst = mlx4_tx_burst;
120 dev->rx_pkt_burst = mlx4_rx_burst;
121 mp_init_msg(dev, &mp_res, param->type);
123 ret = rte_mp_reply(&mp_res, peer);
125 case MLX4_MP_REQ_STOP_RXTX:
126 INFO("port %u stopping datapath", dev->data->port_id);
127 dev->tx_pkt_burst = mlx4_tx_burst_removed;
128 dev->rx_pkt_burst = mlx4_rx_burst_removed;
130 mp_init_msg(dev, &mp_res, param->type);
132 ret = rte_mp_reply(&mp_res, peer);
136 ERROR("port %u invalid mp request type", dev->data->port_id);
143 * Broadcast request of stopping/starting data-path to secondary processes.
146 * Pointer to Ethernet structure.
151 mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx4_mp_req_type type)
153 struct rte_mp_msg mp_req;
154 struct rte_mp_msg *mp_res;
155 struct rte_mp_reply mp_rep;
156 struct mlx4_mp_param *res __rte_unused;
157 struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
161 assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
162 if (!mlx4_shared_data->secondary_cnt)
164 if (type != MLX4_MP_REQ_START_RXTX && type != MLX4_MP_REQ_STOP_RXTX) {
165 ERROR("port %u unknown request (req_type %d)",
166 dev->data->port_id, type);
169 mp_init_msg(dev, &mp_req, type);
170 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
172 ERROR("port %u failed to request stop/start Rx/Tx (%d)",
173 dev->data->port_id, type);
176 if (mp_rep.nb_sent != mp_rep.nb_received) {
177 ERROR("port %u not all secondaries responded (req_type %d)",
178 dev->data->port_id, type);
181 for (i = 0; i < mp_rep.nb_received; i++) {
182 mp_res = &mp_rep.msgs[i];
183 res = (struct mlx4_mp_param *)mp_res->param;
185 ERROR("port %u request failed on secondary #%d",
186 dev->data->port_id, i);
195 * Broadcast request of starting data-path to secondary processes. The request
199 * Pointer to Ethernet structure.
202 mlx4_mp_req_start_rxtx(struct rte_eth_dev *dev)
204 mp_req_on_rxtx(dev, MLX4_MP_REQ_START_RXTX);
208 * Broadcast request of stopping data-path to secondary processes. The request
212 * Pointer to Ethernet structure.
215 mlx4_mp_req_stop_rxtx(struct rte_eth_dev *dev)
217 mp_req_on_rxtx(dev, MLX4_MP_REQ_STOP_RXTX);
221 * IPC message handler of primary process.
224 * Pointer to Ethernet structure.
227 * fd on success, a negative errno value otherwise and rte_errno is set.
230 mlx4_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev)
232 struct rte_mp_msg mp_req;
233 struct rte_mp_msg *mp_res;
234 struct rte_mp_reply mp_rep;
235 struct mlx4_mp_param *res;
236 struct timespec ts = {.tv_sec = MLX4_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
239 assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
240 mp_init_msg(dev, &mp_req, MLX4_MP_REQ_VERBS_CMD_FD);
241 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
243 ERROR("port %u request to primary process failed",
247 assert(mp_rep.nb_received == 1);
248 mp_res = &mp_rep.msgs[0];
249 res = (struct mlx4_mp_param *)mp_res->param;
251 rte_errno = -res->result;
252 ERROR("port %u failed to get command FD from primary process",
257 assert(mp_res->num_fds == 1);
258 ret = mp_res->fds[0];
259 DEBUG("port %u command FD from primary is %d",
260 dev->data->port_id, ret);
267 * Initialize by primary process.
270 mlx4_mp_init_primary(void)
272 assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
273 rte_mp_action_register(MLX4_MP_NAME, mp_primary_handle);
277 * Un-initialize by primary process.
280 mlx4_mp_uninit_primary(void)
282 assert(rte_eal_process_type() == RTE_PROC_PRIMARY);
283 rte_mp_action_unregister(MLX4_MP_NAME);
287 * Initialize by secondary process.
290 mlx4_mp_init_secondary(void)
292 assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
293 rte_mp_action_register(MLX4_MP_NAME, mp_secondary_handle);
297 * Un-initialize by secondary process.
300 mlx4_mp_uninit_secondary(void)
302 assert(rte_eal_process_type() == RTE_PROC_SECONDARY);
303 rte_mp_action_unregister(MLX4_MP_NAME);