1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2019 6WIND S.A.
3 * Copyright 2019 Mellanox Technologies, Ltd
10 #include <rte_ethdev_driver.h>
11 #include <rte_string_fns.h>
13 #include <mlx5_common_mp.h>
16 #include "mlx5_rxtx.h"
17 #include "mlx5_utils.h"
20 mlx5_mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
22 struct rte_mp_msg mp_res;
23 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
24 const struct mlx5_mp_param *param =
25 (const struct mlx5_mp_param *)mp_msg->param;
26 struct rte_eth_dev *dev;
27 struct mlx5_priv *priv;
28 struct mlx5_mr_cache entry;
32 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
33 if (!rte_eth_dev_is_valid_port(param->port_id)) {
35 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
38 dev = &rte_eth_devices[param->port_id];
39 priv = dev->data->dev_private;
40 switch (param->type) {
41 case MLX5_MP_REQ_CREATE_MR:
42 mp_init_msg(&priv->mp_id, &mp_res, param->type);
43 lkey = mlx5_mr_create_primary(dev, &entry, param->args.addr);
44 if (lkey == UINT32_MAX)
45 res->result = -rte_errno;
46 ret = rte_mp_reply(&mp_res, peer);
48 case MLX5_MP_REQ_VERBS_CMD_FD:
49 mp_init_msg(&priv->mp_id, &mp_res, param->type);
51 mp_res.fds[0] = priv->sh->ctx->cmd_fd;
53 ret = rte_mp_reply(&mp_res, peer);
55 case MLX5_MP_REQ_QUEUE_STATE_MODIFY:
56 mp_init_msg(&priv->mp_id, &mp_res, param->type);
57 res->result = mlx5_queue_state_modify_primary
58 (dev, ¶m->args.state_modify);
59 ret = rte_mp_reply(&mp_res, peer);
63 DRV_LOG(ERR, "port %u invalid mp request type",
71 * IPC message handler of a secondary process.
74 * Pointer to Ethernet structure.
76 * Pointer to the peer socket path.
79 * 0 on success, a negative errno value otherwise and rte_errno is set.
82 mlx5_mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
84 struct rte_mp_msg mp_res;
85 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
86 const struct mlx5_mp_param *param =
87 (const struct mlx5_mp_param *)mp_msg->param;
88 struct rte_eth_dev *dev;
89 struct mlx5_priv *priv;
92 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
93 if (!rte_eth_dev_is_valid_port(param->port_id)) {
95 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
98 dev = &rte_eth_devices[param->port_id];
99 priv = dev->data->dev_private;
100 switch (param->type) {
101 case MLX5_MP_REQ_START_RXTX:
102 DRV_LOG(INFO, "port %u starting datapath", dev->data->port_id);
104 dev->rx_pkt_burst = mlx5_select_rx_function(dev);
105 dev->tx_pkt_burst = mlx5_select_tx_function(dev);
106 mp_init_msg(&priv->mp_id, &mp_res, param->type);
108 ret = rte_mp_reply(&mp_res, peer);
110 case MLX5_MP_REQ_STOP_RXTX:
111 DRV_LOG(INFO, "port %u stopping datapath", dev->data->port_id);
112 dev->rx_pkt_burst = removed_rx_burst;
113 dev->tx_pkt_burst = removed_tx_burst;
115 mp_init_msg(&priv->mp_id, &mp_res, param->type);
117 ret = rte_mp_reply(&mp_res, peer);
121 DRV_LOG(ERR, "port %u invalid mp request type",
129 * Broadcast request of stopping/starting data-path to secondary processes.
132 * Pointer to Ethernet structure.
137 mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx5_mp_req_type type)
139 struct rte_mp_msg mp_req;
140 struct rte_mp_msg *mp_res;
141 struct rte_mp_reply mp_rep;
142 struct mlx5_mp_param *res;
143 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
144 struct mlx5_priv *priv = dev->data->dev_private;
148 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
149 if (!mlx5_shared_data->secondary_cnt)
151 if (type != MLX5_MP_REQ_START_RXTX && type != MLX5_MP_REQ_STOP_RXTX) {
152 DRV_LOG(ERR, "port %u unknown request (req_type %d)",
153 dev->data->port_id, type);
156 mp_init_msg(&priv->mp_id, &mp_req, type);
157 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
159 if (rte_errno != ENOTSUP)
160 DRV_LOG(ERR, "port %u failed to request stop/start Rx/Tx (%d)",
161 dev->data->port_id, type);
164 if (mp_rep.nb_sent != mp_rep.nb_received) {
166 "port %u not all secondaries responded (req_type %d)",
167 dev->data->port_id, type);
170 for (i = 0; i < mp_rep.nb_received; i++) {
171 mp_res = &mp_rep.msgs[i];
172 res = (struct mlx5_mp_param *)mp_res->param;
174 DRV_LOG(ERR, "port %u request failed on secondary #%d",
175 dev->data->port_id, i);
184 * Broadcast request of starting data-path to secondary processes. The request
188 * Pointer to Ethernet structure.
191 mlx5_mp_req_start_rxtx(struct rte_eth_dev *dev)
193 mp_req_on_rxtx(dev, MLX5_MP_REQ_START_RXTX);
197 * Broadcast request of stopping data-path to secondary processes. The request
201 * Pointer to Ethernet structure.
204 mlx5_mp_req_stop_rxtx(struct rte_eth_dev *dev)
206 mp_req_on_rxtx(dev, MLX5_MP_REQ_STOP_RXTX);