This source file includes following definitions.
- opal_ethtool_get_speed
1
2
3
4
5
6
7
8
9
10
11
12
13 #include "opal_config.h"
14
15 #include <string.h>
16 #include <limits.h>
17
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24 #ifdef HAVE_SYS_SOCKET_H
25 #include <sys/socket.h>
26 #endif
27 #ifdef HAVE_NET_IF_H
28 #include <net/if.h>
29 #endif
30 #ifdef HAVE_LINUX_ETHTOOL_H
31 #include <linux/ethtool.h>
32 #endif
33 #ifdef HAVE_SYS_IOCTL_H
34 #include <sys/ioctl.h>
35 #endif
36 #ifdef HAVE_LINUX_SOCKIOS_H
37 #include <linux/sockios.h>
38 #endif
39
40 #include "opal/util/ethtool.h"
41 #include "opal/util/if.h"
42 #include "opal/util/string_copy.h"
43
44
45
46
47
48
49 unsigned int
50 opal_ethtool_get_speed (const char *if_name)
51 {
52 unsigned int speed = 0;
53
54 #if defined(HAVE_DECL_SIOCETHTOOL) && defined(HAVE_STRUCT_IFREQ) && defined(HAVE_STRUCT_ETHTOOL_CMD)
55 int sockfd;
56 struct ifreq ifr;
57 struct ethtool_cmd edata = {
58 .cmd = ETHTOOL_GSET,
59 };
60
61 sockfd = socket(PF_INET, SOCK_DGRAM, 0);
62 if (sockfd < 0) {
63 goto out;
64 }
65
66 memset(&ifr, 0, sizeof(struct ifreq));
67 opal_string_copy(ifr.ifr_name, if_name, IF_NAMESIZE);
68 ifr.ifr_data = (char *)&edata;
69
70 if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {
71 goto out;
72 }
73
74 #if HAVE_DECL_ETHTOOL_CMD_SPEED
75 speed = ethtool_cmd_speed(&edata);
76 #elif defined(HAVE_STRUCT_ETHTOOL_CMD_SPEED_HI)
77 speed = (edata.speed_hi << 16) | edata.speed;
78 #else
79 speed = edata.speed;
80 #endif
81 if (UINT_MAX == speed) {
82 speed = 0;
83 }
84
85 out:
86 close(sockfd);
87 #endif
88
89 return speed;
90 }