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>
17 #include "mlx5_rxtx.h"
18 #include "mlx5_utils.h"
21 mlx5_mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
23 struct rte_mp_msg mp_res;
24 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
25 const struct mlx5_mp_param *param =
26 (const struct mlx5_mp_param *)mp_msg->param;
27 struct rte_eth_dev *dev;
28 struct mlx5_priv *priv;
29 struct mr_cache_entry entry;
33 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
34 if (!rte_eth_dev_is_valid_port(param->port_id)) {
36 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
39 dev = &rte_eth_devices[param->port_id];
40 priv = dev->data->dev_private;
41 switch (param->type) {
42 case MLX5_MP_REQ_CREATE_MR:
43 mp_init_msg(&priv->mp_id, &mp_res, param->type);
44 lkey = mlx5_mr_create_primary(priv->sh->pd,
45 &priv->sh->share_cache,
46 &entry, param->args.addr,
47 priv->config.mr_ext_memseg_en);
48 if (lkey == UINT32_MAX)
49 res->result = -rte_errno;
50 ret = rte_mp_reply(&mp_res, peer);
52 case MLX5_MP_REQ_VERBS_CMD_FD:
53 mp_init_msg(&priv->mp_id, &mp_res, param->type);
55 mp_res.fds[0] = priv->sh->ctx->cmd_fd;
57 ret = rte_mp_reply(&mp_res, peer);
59 case MLX5_MP_REQ_QUEUE_STATE_MODIFY:
60 mp_init_msg(&priv->mp_id, &mp_res, param->type);
61 res->result = mlx5_queue_state_modify_primary
62 (dev, ¶m->args.state_modify);
63 ret = rte_mp_reply(&mp_res, peer);
67 DRV_LOG(ERR, "port %u invalid mp request type",
75 * IPC message handler of a secondary process.
78 * Pointer to Ethernet structure.
80 * Pointer to the peer socket path.
83 * 0 on success, a negative errno value otherwise and rte_errno is set.
86 mlx5_mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
88 struct rte_mp_msg mp_res;
89 struct mlx5_mp_param *res = (struct mlx5_mp_param *)mp_res.param;
90 const struct mlx5_mp_param *param =
91 (const struct mlx5_mp_param *)mp_msg->param;
92 struct rte_eth_dev *dev;
93 struct mlx5_priv *priv;
96 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
97 if (!rte_eth_dev_is_valid_port(param->port_id)) {
99 DRV_LOG(ERR, "port %u invalid port ID", param->port_id);
102 dev = &rte_eth_devices[param->port_id];
103 priv = dev->data->dev_private;
104 switch (param->type) {
105 case MLX5_MP_REQ_START_RXTX:
106 DRV_LOG(INFO, "port %u starting datapath", dev->data->port_id);
108 dev->rx_pkt_burst = mlx5_select_rx_function(dev);
109 dev->tx_pkt_burst = mlx5_select_tx_function(dev);
110 mp_init_msg(&priv->mp_id, &mp_res, param->type);
112 ret = rte_mp_reply(&mp_res, peer);
114 case MLX5_MP_REQ_STOP_RXTX:
115 DRV_LOG(INFO, "port %u stopping datapath", dev->data->port_id);
116 dev->rx_pkt_burst = removed_rx_burst;
117 dev->tx_pkt_burst = removed_tx_burst;
119 mp_init_msg(&priv->mp_id, &mp_res, param->type);
121 ret = rte_mp_reply(&mp_res, peer);
125 DRV_LOG(ERR, "port %u invalid mp request type",
133 * Broadcast request of stopping/starting data-path to secondary processes.
136 * Pointer to Ethernet structure.
141 mp_req_on_rxtx(struct rte_eth_dev *dev, enum mlx5_mp_req_type type)
143 struct rte_mp_msg mp_req;
144 struct rte_mp_msg *mp_res;
145 struct rte_mp_reply mp_rep;
146 struct mlx5_mp_param *res;
147 struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
148 struct mlx5_priv *priv = dev->data->dev_private;
152 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
153 if (!mlx5_shared_data->secondary_cnt)
155 if (type != MLX5_MP_REQ_START_RXTX && type != MLX5_MP_REQ_STOP_RXTX) {
156 DRV_LOG(ERR, "port %u unknown request (req_type %d)",
157 dev->data->port_id, type);
160 mp_init_msg(&priv->mp_id, &mp_req, type);
161 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
163 if (rte_errno != ENOTSUP)
164 DRV_LOG(ERR, "port %u failed to request stop/start Rx/Tx (%d)",
165 dev->data->port_id, type);
168 if (mp_rep.nb_sent != mp_rep.nb_received) {
170 "port %u not all secondaries responded (req_type %d)",
171 dev->data->port_id, type);
174 for (i = 0; i < mp_rep.nb_received; i++) {
175 mp_res = &mp_rep.msgs[i];
176 res = (struct mlx5_mp_param *)mp_res->param;
178 DRV_LOG(ERR, "port %u request failed on secondary #%d",
179 dev->data->port_id, i);
188 * Broadcast request of starting data-path to secondary processes. The request
192 * Pointer to Ethernet structure.
195 mlx5_mp_req_start_rxtx(struct rte_eth_dev *dev)
197 mp_req_on_rxtx(dev, MLX5_MP_REQ_START_RXTX);
201 * Broadcast request of stopping data-path to secondary processes. The request
205 * Pointer to Ethernet structure.
208 mlx5_mp_req_stop_rxtx(struct rte_eth_dev *dev)
210 mp_req_on_rxtx(dev, MLX5_MP_REQ_STOP_RXTX);