1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
10 #include <rte_service.h>
11 #include <rte_service_component.h>
14 #include "sfc_service.h"
15 #include "sfc_repr_proxy.h"
19 sfc_repr_proxy_routine(void *arg)
21 struct sfc_repr_proxy *rp = arg;
23 /* Representor proxy boilerplate will be here */
30 sfc_repr_proxy_attach(struct sfc_adapter *sa)
32 struct sfc_repr_proxy *rp = &sa->repr_proxy;
33 struct rte_service_spec service;
38 sfc_log_init(sa, "entry");
40 if (!sfc_repr_supported(sa)) {
41 sfc_log_init(sa, "representors not supported - skip");
45 cid = sfc_get_service_lcore(sa->socket_id);
46 if (cid == RTE_MAX_LCORE && sa->socket_id != SOCKET_ID_ANY) {
47 /* Warn and try to allocate on any NUMA node */
49 "repr proxy: unable to get service lcore at socket %d",
52 cid = sfc_get_service_lcore(SOCKET_ID_ANY);
54 if (cid == RTE_MAX_LCORE) {
56 sfc_err(sa, "repr proxy: failed to get service lcore");
57 goto fail_get_service_lcore;
60 memset(&service, 0, sizeof(service));
61 snprintf(service.name, sizeof(service.name),
62 "net_sfc_%hu_repr_proxy", sfc_sa2shared(sa)->port_id);
63 service.socket_id = rte_lcore_to_socket_id(cid);
64 service.callback = sfc_repr_proxy_routine;
65 service.callback_userdata = rp;
67 rc = rte_service_component_register(&service, &sid);
70 sfc_err(sa, "repr proxy: failed to register service component");
74 rc = rte_service_map_lcore_set(sid, cid, 1);
77 sfc_err(sa, "repr proxy: failed to map lcore");
81 rp->service_core_id = cid;
84 sfc_log_init(sa, "done");
89 rte_service_component_unregister(sid);
93 * No need to rollback service lcore get since
94 * it just makes socket_id based search and remembers it.
97 fail_get_service_lcore:
98 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
103 sfc_repr_proxy_detach(struct sfc_adapter *sa)
105 struct sfc_repr_proxy *rp = &sa->repr_proxy;
107 sfc_log_init(sa, "entry");
109 if (!sfc_repr_supported(sa)) {
110 sfc_log_init(sa, "representors not supported - skip");
114 rte_service_map_lcore_set(rp->service_id, rp->service_core_id, 0);
115 rte_service_component_unregister(rp->service_id);
117 sfc_log_init(sa, "done");
121 sfc_repr_proxy_start(struct sfc_adapter *sa)
123 struct sfc_repr_proxy *rp = &sa->repr_proxy;
126 sfc_log_init(sa, "entry");
129 * The condition to start the proxy is insufficient. It will be
130 * complemented with representor port start/stop support.
132 if (!sfc_repr_supported(sa)) {
133 sfc_log_init(sa, "representors not supported - skip");
137 /* Service core may be in "stopped" state, start it */
138 rc = rte_service_lcore_start(rp->service_core_id);
139 if (rc != 0 && rc != -EALREADY) {
141 sfc_err(sa, "failed to start service core for %s: %s",
142 rte_service_get_name(rp->service_id),
144 goto fail_start_core;
147 /* Run the service */
148 rc = rte_service_component_runstate_set(rp->service_id, 1);
151 sfc_err(sa, "failed to run %s component: %s",
152 rte_service_get_name(rp->service_id),
154 goto fail_component_runstate_set;
156 rc = rte_service_runstate_set(rp->service_id, 1);
159 sfc_err(sa, "failed to run %s: %s",
160 rte_service_get_name(rp->service_id),
162 goto fail_runstate_set;
165 sfc_log_init(sa, "done");
170 rte_service_component_runstate_set(rp->service_id, 0);
172 fail_component_runstate_set:
173 /* Service lcore may be shared and we never stop it */
176 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
181 sfc_repr_proxy_stop(struct sfc_adapter *sa)
183 struct sfc_repr_proxy *rp = &sa->repr_proxy;
186 sfc_log_init(sa, "entry");
188 if (!sfc_repr_supported(sa)) {
189 sfc_log_init(sa, "representors not supported - skip");
193 rc = rte_service_runstate_set(rp->service_id, 0);
195 sfc_err(sa, "failed to stop %s: %s",
196 rte_service_get_name(rp->service_id),
200 rc = rte_service_component_runstate_set(rp->service_id, 0);
202 sfc_err(sa, "failed to stop %s component: %s",
203 rte_service_get_name(rp->service_id),
207 /* Service lcore may be shared and we never stop it */
209 sfc_log_init(sa, "done");