1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 HiSilicon Limited.
6 #include <ethdev_driver.h>
7 #include <rte_string_fns.h>
10 #include "hns3_ethdev.h"
11 #include "hns3_logs.h"
12 #include "hns3_rxtx.h"
15 static bool hns3_inited;
18 * Initialize IPC message.
21 * Pointer to Ethernet structure.
23 * Pointer to message to fill in.
28 mp_init_msg(struct rte_eth_dev *dev, struct rte_mp_msg *msg,
29 enum hns3_mp_req_type type)
31 struct hns3_mp_param *param = (struct hns3_mp_param *)msg->param;
33 memset(msg, 0, sizeof(*msg));
34 strlcpy(msg->name, HNS3_MP_NAME, sizeof(msg->name));
35 msg->len_param = sizeof(*param);
37 param->port_id = dev->data->port_id;
41 * IPC message handler of primary process.
44 * Pointer to Ethernet structure.
46 * Pointer to the peer socket path.
49 * 0 on success, a negative errno value otherwise and rte_errno is set.
52 mp_primary_handle(const struct rte_mp_msg *mp_msg __rte_unused,
53 const void *peer __rte_unused)
59 * IPC message handler of a secondary process.
62 * Pointer to Ethernet structure.
64 * Pointer to the peer socket path.
67 * 0 on success, a negative errno value otherwise and rte_errno is set.
70 mp_secondary_handle(const struct rte_mp_msg *mp_msg, const void *peer)
72 struct rte_mp_msg mp_res;
73 struct hns3_mp_param *res = (struct hns3_mp_param *)mp_res.param;
74 const struct hns3_mp_param *param =
75 (const struct hns3_mp_param *)mp_msg->param;
76 struct rte_eth_dev *dev;
79 if (!rte_eth_dev_is_valid_port(param->port_id)) {
81 PMD_INIT_LOG(ERR, "port %d invalid port ID", param->port_id);
84 dev = &rte_eth_devices[param->port_id];
85 switch (param->type) {
86 case HNS3_MP_REQ_START_RXTX:
87 PMD_INIT_LOG(INFO, "port %u starting datapath",
90 hns3_set_rxtx_function(dev);
91 mp_init_msg(dev, &mp_res, param->type);
93 ret = rte_mp_reply(&mp_res, peer);
95 case HNS3_MP_REQ_STOP_RXTX:
96 PMD_INIT_LOG(INFO, "port %u stopping datapath",
98 hns3_set_rxtx_function(dev);
100 mp_init_msg(dev, &mp_res, param->type);
102 ret = rte_mp_reply(&mp_res, peer);
106 PMD_INIT_LOG(ERR, "port %u invalid mp request type",
114 * Broadcast request of stopping/starting data-path to secondary processes.
117 * Pointer to Ethernet structure.
122 mp_req_on_rxtx(struct rte_eth_dev *dev, enum hns3_mp_req_type type)
124 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
125 struct rte_mp_msg mp_req;
126 struct rte_mp_msg *mp_res;
127 struct rte_mp_reply mp_rep;
128 struct hns3_mp_param *res;
133 if (!hw->secondary_cnt)
135 if (type != HNS3_MP_REQ_START_RXTX && type != HNS3_MP_REQ_STOP_RXTX) {
136 hns3_err(hw, "port %u unknown request (req_type %d)",
137 dev->data->port_id, type);
140 mp_init_msg(dev, &mp_req, type);
141 ts.tv_sec = HNS3_MP_REQ_TIMEOUT_SEC;
143 ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
145 hns3_err(hw, "port %u failed to request stop/start Rx/Tx (%d)",
146 dev->data->port_id, type);
149 if (mp_rep.nb_sent != mp_rep.nb_received) {
151 "port %u not all secondaries responded (req_type %d)",
152 dev->data->port_id, type);
155 for (i = 0; i < mp_rep.nb_received; i++) {
156 mp_res = &mp_rep.msgs[i];
157 res = (struct hns3_mp_param *)mp_res->param;
159 hns3_err(hw, "port %u request failed on secondary #%d",
160 dev->data->port_id, i);
169 * Broadcast request of starting data-path to secondary processes. The request
173 * Pointer to Ethernet structure.
175 void hns3_mp_req_start_rxtx(struct rte_eth_dev *dev)
177 mp_req_on_rxtx(dev, HNS3_MP_REQ_START_RXTX);
181 * Broadcast request of stopping data-path to secondary processes. The request
185 * Pointer to Ethernet structure.
187 void hns3_mp_req_stop_rxtx(struct rte_eth_dev *dev)
189 mp_req_on_rxtx(dev, HNS3_MP_REQ_STOP_RXTX);
193 * Initialize by primary process.
195 int hns3_mp_init_primary(void)
200 /* primary is allowed to not support IPC */
201 ret = rte_mp_action_register(HNS3_MP_NAME, mp_primary_handle);
202 if (ret && rte_errno != ENOTSUP)
212 * Un-initialize by primary process.
214 void hns3_mp_uninit_primary(void)
217 rte_mp_action_unregister(HNS3_MP_NAME);
221 * Initialize by secondary process.
223 int hns3_mp_init_secondary(void)
228 ret = rte_mp_action_register(HNS3_MP_NAME, mp_secondary_handle);