MCPcopy Create free account
hub / github.com/F-Stack/f-stack / mlx5_pmd_socket_init

Function mlx5_pmd_socket_init

dpdk/drivers/net/mlx5/linux/mlx5_socket.c:155–212  ·  view source on GitHub ↗

* Initialise the socket to communicate with external tools. * * @return * 0 on success, a negative value otherwise. */

Source from the content-addressed store, hash-verified

153 * 0 on success, a negative value otherwise.
154 */
155int
156mlx5_pmd_socket_init(void)
157{
158 struct sockaddr_un sun = {
159 .sun_family = AF_UNIX,
160 };
161 int ret;
162 int flags;
163
164 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
165 if (server_socket != -1)
166 return 0;
167 ret = socket(AF_UNIX, SOCK_STREAM, 0);
168 if (ret < 0) {
169 DRV_LOG(WARNING, "Failed to open mlx5 socket: %s",
170 strerror(errno));
171 goto error;
172 }
173 server_socket = ret;
174 flags = fcntl(server_socket, F_GETFL, 0);
175 if (flags == -1)
176 goto close;
177 ret = fcntl(server_socket, F_SETFL, flags | O_NONBLOCK);
178 if (ret < 0)
179 goto close;
180 snprintf(sun.sun_path, sizeof(sun.sun_path), MLX5_SOCKET_PATH,
181 getpid());
182 remove(sun.sun_path);
183 ret = bind(server_socket, (const struct sockaddr *)&sun, sizeof(sun));
184 if (ret < 0) {
185 DRV_LOG(WARNING,
186 "cannot bind mlx5 socket: %s", strerror(errno));
187 goto remove;
188 }
189 ret = listen(server_socket, 0);
190 if (ret < 0) {
191 DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s",
192 strerror(errno));
193 goto remove;
194 }
195 server_intr_handle = mlx5_os_interrupt_handler_create
196 (RTE_INTR_INSTANCE_F_PRIVATE, false,
197 server_socket, mlx5_pmd_socket_handle, NULL);
198 if (server_intr_handle == NULL) {
199 DRV_LOG(WARNING, "cannot register interrupt handler for mlx5 socket: %s",
200 strerror(errno));
201 goto remove;
202 }
203 return 0;
204remove:
205 remove(sun.sun_path);
206close:
207 claim_zero(close(server_socket));
208 server_socket = -1;
209error:
210 DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno));
211 return -errno;
212}

Callers 1

mlx5_os_net_probeFunction · 0.85

Calls 8

rte_eal_process_typeFunction · 0.85
snprintfFunction · 0.85
socketClass · 0.50
fcntlFunction · 0.50
bindFunction · 0.50
listenFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected