1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include <linux/ethtool.h>
7 #include "conf-parser.h"
8 #include "missing_network.h"
12 /* we can't use DUPLEX_ prefix, as it
13 * clashes with <linux/ethtool.h> */
15 DUP_HALF
= DUPLEX_HALF
,
16 DUP_FULL
= DUPLEX_FULL
,
21 typedef enum WakeOnLan
{
34 typedef enum NetDevFeature
{
41 _NET_DEV_FEAT_INVALID
= -1
44 typedef enum NetDevPort
{
45 NET_DEV_PORT_TP
= 0x00,
46 NET_DEV_PORT_AUI
= 0x01,
47 NET_DEV_PORT_MII
= 0x02,
48 NET_DEV_PORT_FIBRE
= 0x03,
49 NET_DEV_PORT_BNC
= 0x04,
50 NET_DEV_PORT_DA
= 0x05,
51 NET_DEV_PORT_NONE
= 0xef,
52 NET_DEV_PORT_OTHER
= 0xff,
54 _NET_DEV_PORT_INVALID
= -1
57 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
58 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
60 /* layout of the struct passed from/to userland */
61 struct ethtool_link_usettings
{
62 struct ethtool_link_settings base
;
65 uint32_t supported
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
66 uint32_t advertising
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
67 uint32_t lp_advertising
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
71 typedef struct netdev_channels
{
75 uint32_t combined_count
;
80 bool combined_count_set
;
83 int ethtool_connect(int *ret
);
85 int ethtool_get_driver(int *fd
, const char *ifname
, char **ret
);
86 int ethtool_set_speed(int *fd
, const char *ifname
, unsigned speed
, Duplex duplex
);
87 int ethtool_set_wol(int *fd
, const char *ifname
, WakeOnLan wol
);
88 int ethtool_set_features(int *fd
, const char *ifname
, int *features
);
89 int ethtool_set_glinksettings(int *fd
, const char *ifname
, struct link_config
*link
);
90 int ethtool_set_channels(int *fd
, const char *ifname
, netdev_channels
*channels
);
92 const char *duplex_to_string(Duplex d
) _const_
;
93 Duplex
duplex_from_string(const char *d
) _pure_
;
95 const char *wol_to_string(WakeOnLan wol
) _const_
;
96 WakeOnLan
wol_from_string(const char *wol
) _pure_
;
98 const char *port_to_string(NetDevPort port
) _const_
;
99 NetDevPort
port_from_string(const char *port
) _pure_
;
101 const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val
) _const_
;
102 enum ethtool_link_mode_bit_indices
ethtool_link_mode_bit_from_string(const char *str
) _pure_
;
104 CONFIG_PARSER_PROTOTYPE(config_parse_duplex
);
105 CONFIG_PARSER_PROTOTYPE(config_parse_wol
);
106 CONFIG_PARSER_PROTOTYPE(config_parse_port
);
107 CONFIG_PARSER_PROTOTYPE(config_parse_channel
);
108 CONFIG_PARSER_PROTOTYPE(config_parse_advertise
);