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>
14 #include <mlx5_common_mr.h>
15 #include <mlx5_malloc.h>
18 #include "mlx5_rxtx.h"
19 #include "mlx5_utils.h"
22 mlx5_mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
24 struct rte_mp_msg mp_res;
25 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
26 const struct mlx5_mp_param *param =
27 (const struct mlx5_mp_param *)mp_msg->param;
28 struct rte_eth_dev *dev;
29 struct mlx5_priv *priv;
30 struct mr_cache_entry entry;
34 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
35 if (!rte_eth_dev_is_valid_port(param->port_id)) {
37 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
40 dev = &rte_eth_devices[param->port_id];
41 priv = dev->data->dev_private;
42 switch (param->type) {
43 case MLX5_MP_REQ_CREATE_MR:
44 mp_init_msg(&priv->mp_id, &mp_res, param->type);
45 lkey = mlx5_mr_create_primary(priv->sh->pd,
46 &priv->sh->share_cache,
47 &entry, param->args.addr,
48 priv->config.mr_ext_memseg_en);
49 if (lkey == UINT32_MAX)
50 res->result = -rte_errno;
51 ret = rte_mp_reply(&mp_res, peer);
53 case MLX5_MP_REQ_VERBS_CMD_FD:
54 mp_init_msg(&priv->mp_id, &mp_res, param->type);
56 mp_res.fds[0] = ((struct ibv_context *)priv->sh->ctx)->cmd_fd;
58 ret = rte_mp_reply(&mp_res, peer);
60 case MLX5_MP_REQ_QUEUE_STATE_MODIFY:
61 mp_init_msg(&priv->mp_id, &mp_res, param->type);
62 res->result = mlx5_queue_state_modify_primary
63 (dev, ¶m->args.state_modify);
64 ret = rte_mp_reply(&mp_res, peer);
68 DRV_LOG(ERR, "port %u invalid mp request type",
76 * IPC message handler of a secondary process.
79 * Pointer to Ethernet structure.
81 * Pointer to the peer socket path.
84 * 0 on success, a negative errno value otherwise and rte_errno is set.
87 mlx5_mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
89 struct rte_mp_msg mp_res;
90 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
91 const struct mlx5_mp_param *param =
92 (const struct mlx5_mp_param *)mp_msg->param;
93 struct rte_eth_dev *dev;
94 struct mlx5_priv *priv;
97 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
98 if (!rte_eth_dev_is_valid_port(param->port_id)) {
100 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
103 dev = &rte_eth_devices[param->port_id];
104 priv = dev->data->dev_private;
105 switch (param->type) {
106 case MLX5_MP_REQ_START_RXTX:
107 DRV_LOG(INFO, "port %u starting datapath", dev->data->port_id);
109 dev->rx_pkt_burst = mlx5_select_rx_function(dev);
110 dev->tx_pkt_burst = mlx5_select_tx_function(dev);
111 mp_init_msg(&priv->mp_id, &mp_res, param->type);
113 ret = rte_mp_reply(&mp_res, peer);
115 case MLX5_MP_REQ_STOP_RXTX:
116 DRV_LOG(INFO, "port %u stopping datapath", dev->data->port_id);
117 dev->rx_pkt_burst = removed_rx_burst;
118 dev->tx_pkt_burst = removed_tx_burst;
120 mp_init_msg(&priv->mp_id, &mp_res, param->type);
122 ret = rte_mp_reply(&mp_res, peer);
126 DRV_LOG(ERR, "port %u invalid mp request type",
134 * Broadcast request of stopping/starting data-path to secondary processes.
137 * Pointer to Ethernet structure.
142 mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx5_mp_req_type type)
144 struct rte_mp_msg mp_req;
145 struct rte_mp_msg *mp_res;
146 struct rte_mp_reply mp_rep;
147 struct mlx5_mp_param *res;
148 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
149 struct mlx5_priv *priv = dev->data->dev_private;
153 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
154 if (!mlx5_shared_data->secondary_cnt)
156 if (type != MLX5_MP_REQ_START_RXTX && type != MLX5_MP_REQ_STOP_RXTX) {
157 DRV_LOG(ERR, "port %u unknown request (req_type %d)",
158 dev->data->port_id, type);
161 mp_init_msg(&priv->mp_id, &mp_req, type);
162 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
164 if (rte_errno != ENOTSUP)
165 DRV_LOG(ERR, "port %u failed to request stop/start Rx/Tx (%d)",
166 dev->data->port_id, type);
169 if (mp_rep.nb_sent != mp_rep.nb_received) {
171 "port %u not all secondaries responded (req_type %d)",
172 dev->data->port_id, type);
175 for (i = 0; i < mp_rep.nb_received; i++) {
176 mp_res = &mp_rep.msgs[i];
177 res = (struct mlx5_mp_param *)mp_res->param;
179 DRV_LOG(ERR, "port %u request failed on secondary #%d",
180 dev->data->port_id, i);
185 mlx5_free(mp_rep.msgs);
189 * Broadcast request of starting data-path to secondary processes. The request
193 * Pointer to Ethernet structure.
196 mlx5_mp_req_start_rxtx(struct rte_eth_dev *dev)
198 mp_req_on_rxtx(dev, MLX5_MP_REQ_START_RXTX);
202 * Broadcast request of stopping data-path to secondary processes. The request
206 * Pointer to Ethernet structure.
209 mlx5_mp_req_stop_rxtx(struct rte_eth_dev *dev)
211 mp_req_on_rxtx(dev, MLX5_MP_REQ_STOP_RXTX);