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_os_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);
66 case MLX5_MP_REQ_QUEUE_RX_STOP:
67 mp_init_msg(&priv->mp_id, &mp_res, param->type);
68 res->result = mlx5_rx_queue_stop_primary
69 (dev, param->args.queue_id.queue_id);
70 ret = rte_mp_reply(&mp_res, peer);
72 case MLX5_MP_REQ_QUEUE_RX_START:
73 mp_init_msg(&priv->mp_id, &mp_res, param->type);
74 res->result = mlx5_rx_queue_start_primary
75 (dev, param->args.queue_id.queue_id);
76 ret = rte_mp_reply(&mp_res, peer);
78 case MLX5_MP_REQ_QUEUE_TX_STOP:
79 mp_init_msg(&priv->mp_id, &mp_res, param->type);
80 res->result = mlx5_tx_queue_stop_primary
81 (dev, param->args.queue_id.queue_id);
82 ret = rte_mp_reply(&mp_res, peer);
84 case MLX5_MP_REQ_QUEUE_TX_START:
85 mp_init_msg(&priv->mp_id, &mp_res, param->type);
86 res->result = mlx5_tx_queue_start_primary
87 (dev, param->args.queue_id.queue_id);
88 ret = rte_mp_reply(&mp_res, peer);
92 DRV_LOG(ERR, "port %u invalid mp request type",
100 * IPC message handler of a secondary process.
103 * Pointer to Ethernet structure.
105 * Pointer to the peer socket path.
108 * 0 on success, a negative errno value otherwise and rte_errno is set.
111 mlx5_mp_os_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
113 struct rte_mp_msg mp_res;
114 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
115 const struct mlx5_mp_param *param =
116 (const struct mlx5_mp_param *)mp_msg->param;
117 struct rte_eth_dev *dev;
118 struct mlx5_priv *priv;
121 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
122 if (!rte_eth_dev_is_valid_port(param->port_id)) {
124 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
127 dev = &rte_eth_devices[param->port_id];
128 priv = dev->data->dev_private;
129 switch (param->type) {
130 case MLX5_MP_REQ_START_RXTX:
131 DRV_LOG(INFO, "port %u starting datapath", dev->data->port_id);
133 dev->rx_pkt_burst = mlx5_select_rx_function(dev);
134 dev->tx_pkt_burst = mlx5_select_tx_function(dev);
135 mp_init_msg(&priv->mp_id, &mp_res, param->type);
137 ret = rte_mp_reply(&mp_res, peer);
139 case MLX5_MP_REQ_STOP_RXTX:
140 DRV_LOG(INFO, "port %u stopping datapath", dev->data->port_id);
141 dev->rx_pkt_burst = removed_rx_burst;
142 dev->tx_pkt_burst = removed_tx_burst;
144 mp_init_msg(&priv->mp_id, &mp_res, param->type);
146 ret = rte_mp_reply(&mp_res, peer);
150 DRV_LOG(ERR, "port %u invalid mp request type",
158 * Broadcast request of stopping/starting data-path to secondary processes.
161 * Pointer to Ethernet structure.
166 mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx5_mp_req_type type)
168 struct rte_mp_msg mp_req;
169 struct rte_mp_msg *mp_res;
170 struct rte_mp_reply mp_rep;
171 struct mlx5_mp_param *res;
172 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
173 struct mlx5_priv *priv = dev->data->dev_private;
177 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
178 if (!mlx5_shared_data->secondary_cnt)
180 if (type != MLX5_MP_REQ_START_RXTX && type != MLX5_MP_REQ_STOP_RXTX) {
181 DRV_LOG(ERR, "port %u unknown request (req_type %d)",
182 dev->data->port_id, type);
185 mp_init_msg(&priv->mp_id, &mp_req, type);
186 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
188 if (rte_errno != ENOTSUP)
189 DRV_LOG(ERR, "port %u failed to request stop/start Rx/Tx (%d)",
190 dev->data->port_id, type);
193 if (mp_rep.nb_sent != mp_rep.nb_received) {
195 "port %u not all secondaries responded (req_type %d)",
196 dev->data->port_id, type);
199 for (i = 0; i < mp_rep.nb_received; i++) {
200 mp_res = &mp_rep.msgs[i];
201 res = (struct mlx5_mp_param *)mp_res->param;
203 DRV_LOG(ERR, "port %u request failed on secondary #%d",
204 dev->data->port_id, i);
209 mlx5_free(mp_rep.msgs);
213 * Broadcast request of starting data-path to secondary processes. The request
217 * Pointer to Ethernet structure.
220 mlx5_mp_os_req_start_rxtx(struct rte_eth_dev *dev)
222 mp_req_on_rxtx(dev, MLX5_MP_REQ_START_RXTX);
226 * Broadcast request of stopping data-path to secondary processes. The request
230 * Pointer to Ethernet structure.
233 mlx5_mp_os_req_stop_rxtx(struct rte_eth_dev *dev)
235 mp_req_on_rxtx(dev, MLX5_MP_REQ_STOP_RXTX);
239 * Request Verbs Rx/Tx queue stop or start to the primary process.
242 * Pointer to Ethernet structure.
244 * Queue ID to control.
247 * MLX5_MP_REQ_QUEUE_RX_START - start Rx queue
248 * MLX5_MP_REQ_QUEUE_TX_START - stop Tx queue
249 * MLX5_MP_REQ_QUEUE_RX_STOP - stop Rx queue
250 * MLX5_MP_REQ_QUEUE_TX_STOP - stop Tx queue
252 * 0 on success, a negative errno value otherwise and
256 mlx5_mp_os_req_queue_control(struct rte_eth_dev *dev, uint16_t queue_id,
257 enum mlx5_mp_req_type req_type)
259 struct rte_mp_msg mp_req;
260 struct rte_mp_msg *mp_res;
261 struct rte_mp_reply mp_rep;
262 struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
263 struct mlx5_mp_param *res;
264 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
265 struct mlx5_priv *priv;
268 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
269 priv = dev->data->dev_private;
270 mp_init_msg(&priv->mp_id, &mp_req, req_type);
271 req->args.queue_id.queue_id = queue_id;
272 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
274 DRV_LOG(ERR, "port %u request to primary process failed",
278 MLX5_ASSERT(mp_rep.nb_received == 1);
279 mp_res = &mp_rep.msgs[0];
280 res = (struct mlx5_mp_param *)mp_res->param;