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

Function mlx4_get_ifname

dpdk/drivers/net/mlx4/mlx4_ethdev.c:60–132  ·  view source on GitHub ↗

* Get interface name from private structure. * * @param[in] priv * Pointer to private structure. * @param[out] ifname * Interface name output buffer. * * @return * 0 on success, negative errno value otherwise and rte_errno is set. */

Source from the content-addressed store, hash-verified

58 * 0 on success, negative errno value otherwise and rte_errno is set.
59 */
60int
61mlx4_get_ifname(const struct mlx4_priv *priv, char (*ifname)[IF_NAMESIZE])
62{
63 DIR *dir;
64 struct dirent *dent;
65 unsigned int dev_type = 0;
66 unsigned int dev_port_prev = ~0u;
67 char match[IF_NAMESIZE] = "";
68
69 {
70 MKSTR(path, "%s/device/net", priv->ctx->device->ibdev_path);
71
72 dir = opendir(path);
73 if (dir == NULL) {
74 rte_errno = errno;
75 return -rte_errno;
76 }
77 }
78 while ((dent = readdir(dir)) != NULL) {
79 char *name = dent->d_name;
80 FILE *file;
81 unsigned int dev_port;
82 int r;
83
84 if ((name[0] == '.') &&
85 ((name[1] == '\0') ||
86 ((name[1] == '.') && (name[2] == '\0'))))
87 continue;
88
89 MKSTR(path, "%s/device/net/%s/%s",
90 priv->ctx->device->ibdev_path, name,
91 (dev_type ? "dev_id" : "dev_port"));
92
93 file = fopen(path, "rb");
94 if (file == NULL) {
95 if (errno != ENOENT)
96 continue;
97 /*
98 * Switch to dev_id when dev_port does not exist as
99 * is the case with Linux kernel versions < 3.15.
100 */
101try_dev_id:
102 match[0] = '\0';
103 if (dev_type)
104 break;
105 dev_type = 1;
106 dev_port_prev = ~0u;
107 rewinddir(dir);
108 continue;
109 }
110 r = fscanf(file, (dev_type ? "%x" : "%u"), &dev_port);
111 fclose(file);
112 if (r != 1)
113 continue;
114 /*
115 * Switch to dev_id when dev_port returns the same value for
116 * all ports. May happen when using a MOFED release older than
117 * 3.0 with a Linux kernel >= 3.15.

Callers 2

mlx4_ifreqFunction · 0.85
mlx4_pci_probeFunction · 0.85

Calls 5

opendirFunction · 0.85
readdirFunction · 0.85
closedirFunction · 0.85
strncpyFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected