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_adapter_shared * const sas = sfc_sa2shared(sa);
33 struct sfc_repr_proxy *rp = &sa->repr_proxy;
34 struct rte_service_spec service;
39 sfc_log_init(sa, "entry");
41 if (!sfc_repr_available(sas)) {
42 sfc_log_init(sa, "representors not supported - skip");
46 cid = sfc_get_service_lcore(sa->socket_id);
47 if (cid == RTE_MAX_LCORE && sa->socket_id != SOCKET_ID_ANY) {
48 /* Warn and try to allocate on any NUMA node */
50 "repr proxy: unable to get service lcore at socket %d",
53 cid = sfc_get_service_lcore(SOCKET_ID_ANY);
55 if (cid == RTE_MAX_LCORE) {
57 sfc_err(sa, "repr proxy: failed to get service lcore");
58 goto fail_get_service_lcore;
61 memset(&service, 0, sizeof(service));
62 snprintf(service.name, sizeof(service.name),
63 "net_sfc_%hu_repr_proxy", sfc_sa2shared(sa)->port_id);
64 service.socket_id = rte_lcore_to_socket_id(cid);
65 service.callback = sfc_repr_proxy_routine;
66 service.callback_userdata = rp;
68 rc = rte_service_component_register(&service, &sid);
71 sfc_err(sa, "repr proxy: failed to register service component");
75 rc = rte_service_map_lcore_set(sid, cid, 1);
78 sfc_err(sa, "repr proxy: failed to map lcore");
82 rp->service_core_id = cid;
85 sfc_log_init(sa, "done");
90 rte_service_component_unregister(sid);
94 * No need to rollback service lcore get since
95 * it just makes socket_id based search and remembers it.
98 fail_get_service_lcore:
99 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
104 sfc_repr_proxy_detach(struct sfc_adapter *sa)
106 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
107 struct sfc_repr_proxy *rp = &sa->repr_proxy;
109 sfc_log_init(sa, "entry");
111 if (!sfc_repr_available(sas)) {
112 sfc_log_init(sa, "representors not supported - skip");
116 rte_service_map_lcore_set(rp->service_id, rp->service_core_id, 0);
117 rte_service_component_unregister(rp->service_id);
119 sfc_log_init(sa, "done");
123 sfc_repr_proxy_start(struct sfc_adapter *sa)
125 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
126 struct sfc_repr_proxy *rp = &sa->repr_proxy;
129 sfc_log_init(sa, "entry");
132 * The condition to start the proxy is insufficient. It will be
133 * complemented with representor port start/stop support.
135 if (!sfc_repr_available(sas)) {
136 sfc_log_init(sa, "representors not supported - skip");
140 /* Service core may be in "stopped" state, start it */
141 rc = rte_service_lcore_start(rp->service_core_id);
142 if (rc != 0 && rc != -EALREADY) {
144 sfc_err(sa, "failed to start service core for %s: %s",
145 rte_service_get_name(rp->service_id),
147 goto fail_start_core;
150 /* Run the service */
151 rc = rte_service_component_runstate_set(rp->service_id, 1);
154 sfc_err(sa, "failed to run %s component: %s",
155 rte_service_get_name(rp->service_id),
157 goto fail_component_runstate_set;
159 rc = rte_service_runstate_set(rp->service_id, 1);
162 sfc_err(sa, "failed to run %s: %s",
163 rte_service_get_name(rp->service_id),
165 goto fail_runstate_set;
168 sfc_log_init(sa, "done");
173 rte_service_component_runstate_set(rp->service_id, 0);
175 fail_component_runstate_set:
176 /* Service lcore may be shared and we never stop it */
179 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
184 sfc_repr_proxy_stop(struct sfc_adapter *sa)
186 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
187 struct sfc_repr_proxy *rp = &sa->repr_proxy;
190 sfc_log_init(sa, "entry");
192 if (!sfc_repr_available(sas)) {
193 sfc_log_init(sa, "representors not supported - skip");
197 rc = rte_service_runstate_set(rp->service_id, 0);
199 sfc_err(sa, "failed to stop %s: %s",
200 rte_service_get_name(rp->service_id),
204 rc = rte_service_component_runstate_set(rp->service_id, 0);
206 sfc_err(sa, "failed to stop %s component: %s",
207 rte_service_get_name(rp->service_id),
211 /* Service lcore may be shared and we never stop it */
213 sfc_log_init(sa, "done");