1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2019 6WIND S.A.
3 * Copyright 2019 Mellanox Technologies, Ltd
10 #include <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"
20 #include "mlx5_utils.h"
23 mlx5_mp_os_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
25 struct rte_mp_msg mp_res;
26 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
27 const struct mlx5_mp_param *param =
28 (const struct mlx5_mp_param *)mp_msg->param;
29 struct rte_eth_dev *dev;
30 struct mlx5_priv *priv;
31 struct mr_cache_entry entry;
35 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
36 if (!rte_eth_dev_is_valid_port(param->port_id)) {
38 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
41 dev = &rte_eth_devices[param->port_id];
42 priv = dev->data->dev_private;
43 switch (param->type) {
44 case MLX5_MP_REQ_CREATE_MR:
45 mp_init_msg(&priv->mp_id, &mp_res, param->type);
46 lkey = mlx5_mr_create_primary(priv->sh->pd,
47 &priv->sh->share_cache,
48 &entry, param->args.addr,
49 priv->config.mr_ext_memseg_en);
50 if (lkey == UINT32_MAX)
51 res->result = -rte_errno;
52 ret = rte_mp_reply(&mp_res, peer);
54 case MLX5_MP_REQ_VERBS_CMD_FD:
55 mp_init_msg(&priv->mp_id, &mp_res, param->type);
57 mp_res.fds[0] = ((struct ibv_context *)priv->sh->ctx)->cmd_fd;
59 ret = rte_mp_reply(&mp_res, peer);
61 case MLX5_MP_REQ_QUEUE_STATE_MODIFY:
62 mp_init_msg(&priv->mp_id, &mp_res, param->type);
63 res->result = mlx5_queue_state_modify_primary
64 (dev, ¶m->args.state_modify);
65 ret = rte_mp_reply(&mp_res, peer);
67 case MLX5_MP_REQ_QUEUE_RX_STOP:
68 mp_init_msg(&priv->mp_id, &mp_res, param->type);
69 res->result = mlx5_rx_queue_stop_primary
70 (dev, param->args.queue_id.queue_id);
71 ret = rte_mp_reply(&mp_res, peer);
73 case MLX5_MP_REQ_QUEUE_RX_START:
74 mp_init_msg(&priv->mp_id, &mp_res, param->type);
75 res->result = mlx5_rx_queue_start_primary
76 (dev, param->args.queue_id.queue_id);
77 ret = rte_mp_reply(&mp_res, peer);
79 case MLX5_MP_REQ_QUEUE_TX_STOP:
80 mp_init_msg(&priv->mp_id, &mp_res, param->type);
81 res->result = mlx5_tx_queue_stop_primary
82 (dev, param->args.queue_id.queue_id);
83 ret = rte_mp_reply(&mp_res, peer);
85 case MLX5_MP_REQ_QUEUE_TX_START:
86 mp_init_msg(&priv->mp_id, &mp_res, param->type);
87 res->result = mlx5_tx_queue_start_primary
88 (dev, param->args.queue_id.queue_id);
89 ret = rte_mp_reply(&mp_res, peer);
93 DRV_LOG(ERR, "port %u invalid mp request type",
101 * IPC message handler of a secondary process.
104 * Pointer to Ethernet structure.
106 * Pointer to the peer socket path.
109 * 0 on success, a negative errno value otherwise and rte_errno is set.
112 mlx5_mp_os_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
114 struct rte_mp_msg mp_res;
115 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
116 const struct mlx5_mp_param *param =
117 (const struct mlx5_mp_param *)mp_msg->param;
118 struct rte_eth_dev *dev;
119 struct mlx5_proc_priv *ppriv;
120 struct mlx5_priv *priv;
123 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
124 if (!rte_eth_dev_is_valid_port(param->port_id)) {
126 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
129 dev = &rte_eth_devices[param->port_id];
130 priv = dev->data->dev_private;
131 switch (param->type) {
132 case MLX5_MP_REQ_START_RXTX:
133 DRV_LOG(INFO, "port %u starting datapath", dev->data->port_id);
135 dev->rx_pkt_burst = mlx5_select_rx_function(dev);
136 dev->tx_pkt_burst = mlx5_select_tx_function(dev);
137 ppriv = (struct mlx5_proc_priv *)dev->process_private;
138 /* If Tx queue number changes, re-initialize UAR. */
139 if (ppriv->uar_table_sz != priv->txqs_n) {
140 mlx5_tx_uar_uninit_secondary(dev);
141 mlx5_proc_priv_uninit(dev);
142 ret = mlx5_proc_priv_init(dev);
145 ret = mlx5_tx_uar_init_secondary(dev, mp_msg->fds[0]);
147 mlx5_proc_priv_uninit(dev);
151 mp_init_msg(&priv->mp_id, &mp_res, param->type);
153 ret = rte_mp_reply(&mp_res, peer);
155 case MLX5_MP_REQ_STOP_RXTX:
156 DRV_LOG(INFO, "port %u stopping datapath", dev->data->port_id);
157 dev->rx_pkt_burst = removed_rx_burst;
158 dev->tx_pkt_burst = removed_tx_burst;
160 mp_init_msg(&priv->mp_id, &mp_res, param->type);
162 ret = rte_mp_reply(&mp_res, peer);
166 DRV_LOG(ERR, "port %u invalid mp request type",
174 * Broadcast request of stopping/starting data-path to secondary processes.
177 * Pointer to Ethernet structure.
182 mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx5_mp_req_type type)
184 struct rte_mp_msg mp_req;
185 struct rte_mp_msg *mp_res;
186 struct rte_mp_reply mp_rep;
187 struct mlx5_mp_param *res;
188 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
189 struct mlx5_priv *priv = dev->data->dev_private;
193 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
194 if (!mlx5_shared_data->secondary_cnt)
196 if (type != MLX5_MP_REQ_START_RXTX && type != MLX5_MP_REQ_STOP_RXTX) {
197 DRV_LOG(ERR, "port %u unknown request (req_type %d)",
198 dev->data->port_id, type);
201 mp_init_msg(&priv->mp_id, &mp_req, type);
202 if (type == MLX5_MP_REQ_START_RXTX) {
204 mp_req.fds[0] = ((struct ibv_context *)priv->sh->ctx)->cmd_fd;
206 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
208 if (rte_errno != ENOTSUP)
209 DRV_LOG(ERR, "port %u failed to request stop/start Rx/Tx (%d)",
210 dev->data->port_id, type);
213 if (mp_rep.nb_sent != mp_rep.nb_received) {
215 "port %u not all secondaries responded (req_type %d)",
216 dev->data->port_id, type);
219 for (i = 0; i < mp_rep.nb_received; i++) {
220 mp_res = &mp_rep.msgs[i];
221 res = (struct mlx5_mp_param *)mp_res->param;
223 DRV_LOG(ERR, "port %u request failed on secondary #%d",
224 dev->data->port_id, i);
229 mlx5_free(mp_rep.msgs);
233 * Broadcast request of starting data-path to secondary processes. The request
237 * Pointer to Ethernet structure.
240 mlx5_mp_os_req_start_rxtx(struct rte_eth_dev *dev)
242 mp_req_on_rxtx(dev, MLX5_MP_REQ_START_RXTX);
246 * Broadcast request of stopping data-path to secondary processes. The request
250 * Pointer to Ethernet structure.
253 mlx5_mp_os_req_stop_rxtx(struct rte_eth_dev *dev)
255 mp_req_on_rxtx(dev, MLX5_MP_REQ_STOP_RXTX);
259 * Request Verbs Rx/Tx queue stop or start to the primary process.
262 * Pointer to Ethernet structure.
264 * Queue ID to control.
267 * MLX5_MP_REQ_QUEUE_RX_START - start Rx queue
268 * MLX5_MP_REQ_QUEUE_TX_START - stop Tx queue
269 * MLX5_MP_REQ_QUEUE_RX_STOP - stop Rx queue
270 * MLX5_MP_REQ_QUEUE_TX_STOP - stop Tx queue
272 * 0 on success, a negative errno value otherwise and
276 mlx5_mp_os_req_queue_control(struct rte_eth_dev *dev, uint16_t queue_id,
277 enum mlx5_mp_req_type req_type)
279 struct rte_mp_msg mp_req;
280 struct rte_mp_msg *mp_res;
281 struct rte_mp_reply mp_rep;
282 struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
283 struct mlx5_mp_param *res;
284 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
285 struct mlx5_priv *priv;
288 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
289 priv = dev->data->dev_private;
290 mp_init_msg(&priv->mp_id, &mp_req, req_type);
291 req->args.queue_id.queue_id = queue_id;
292 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
294 DRV_LOG(ERR, "port %u request to primary process failed",
298 MLX5_ASSERT(mp_rep.nb_received == 1);
299 mp_res = &mp_rep.msgs[0];
300 res = (struct mlx5_mp_param *)mp_res->param;