1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include <net/ethernet.h>
6 #include <linux/ethtool.h>
8 #include "conf-parser.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
{
43 _NET_DEV_FEAT_INVALID
= -1
46 typedef enum NetDevPort
{
47 NET_DEV_PORT_TP
= PORT_TP
,
48 NET_DEV_PORT_AUI
= PORT_AUI
,
49 NET_DEV_PORT_MII
= PORT_MII
,
50 NET_DEV_PORT_FIBRE
= PORT_FIBRE
,
51 NET_DEV_PORT_BNC
= PORT_BNC
,
52 NET_DEV_PORT_DA
= PORT_DA
,
53 NET_DEV_PORT_NONE
= PORT_NONE
,
54 NET_DEV_PORT_OTHER
= PORT_OTHER
,
56 _NET_DEV_PORT_INVALID
= -1
59 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
60 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
62 /* layout of the struct passed from/to userland */
63 struct ethtool_link_usettings
{
64 struct ethtool_link_settings base
;
67 uint32_t supported
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
68 uint32_t advertising
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
69 uint32_t lp_advertising
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
73 typedef struct netdev_channels
{
77 uint32_t combined_count
;
82 bool combined_count_set
;
85 typedef struct netdev_ring_param
{
87 uint32_t rx_mini_pending
;
88 uint32_t rx_jumbo_pending
;
92 bool rx_mini_pending_set
;
93 bool rx_jumbo_pending_set
;
97 int ethtool_get_driver(int *ethtool_fd
, const char *ifname
, char **ret
);
98 int ethtool_get_link_info(int *ethtool_fd
, const char *ifname
,
99 int *ret_autonegotiation
, uint64_t *ret_speed
,
100 Duplex
*ret_duplex
, NetDevPort
*ret_port
);
101 int ethtool_get_permanent_macaddr(int *ethtool_fd
, const char *ifname
, struct ether_addr
*ret
);
102 int ethtool_set_speed(int *ethtool_fd
, const char *ifname
, unsigned speed
, Duplex duplex
);
103 int ethtool_set_wol(int *ethtool_fd
, const char *ifname
, WakeOnLan wol
);
104 int ethtool_set_nic_buffer_size(int *ethtool_fd
, const char *ifname
, netdev_ring_param
*ring
);
105 int ethtool_set_features(int *ethtool_fd
, const char *ifname
, int *features
);
106 int ethtool_set_glinksettings(int *ethtool_fd
, const char *ifname
,
107 int autonegotiation
, uint32_t advertise
[static N_ADVERTISE
],
108 uint64_t speed
, Duplex duplex
, NetDevPort port
);
109 int ethtool_set_channels(int *ethtool_fd
, const char *ifname
, netdev_channels
*channels
);
110 int ethtool_set_flow_control(int *fd
, const char *ifname
, int rx
, int tx
, int autoneg
);
112 const char *duplex_to_string(Duplex d
) _const_
;
113 Duplex
duplex_from_string(const char *d
) _pure_
;
115 const char *wol_to_string(WakeOnLan wol
) _const_
;
116 WakeOnLan
wol_from_string(const char *wol
) _pure_
;
118 const char *port_to_string(NetDevPort port
) _const_
;
119 NetDevPort
port_from_string(const char *port
) _pure_
;
121 const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val
) _const_
;
122 enum ethtool_link_mode_bit_indices
ethtool_link_mode_bit_from_string(const char *str
) _pure_
;
124 CONFIG_PARSER_PROTOTYPE(config_parse_duplex
);
125 CONFIG_PARSER_PROTOTYPE(config_parse_wol
);
126 CONFIG_PARSER_PROTOTYPE(config_parse_port
);
127 CONFIG_PARSER_PROTOTYPE(config_parse_channel
);
128 CONFIG_PARSER_PROTOTYPE(config_parse_advertise
);
129 CONFIG_PARSER_PROTOTYPE(config_parse_nic_buffer_size
);