1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include <net/ethernet.h>
6 #include <linux/ethtool.h>
8 #include "conf-parser.h"
9 #include "ether-addr-util.h"
13 /* we can't use DUPLEX_ prefix, as it
14 * clashes with <linux/ethtool.h> */
16 DUP_HALF
= DUPLEX_HALF
,
17 DUP_FULL
= DUPLEX_FULL
,
19 _DUP_INVALID
= -EINVAL
,
22 typedef enum NetDevFeature
{
26 NET_DEV_FEAT_IPV6_CSUM
,
28 NET_DEV_FEAT_FRAGLIST
,
29 NET_DEV_FEAT_HW_VLAN_CTAG_TX
,
30 NET_DEV_FEAT_HW_VLAN_CTAG_RX
,
31 NET_DEV_FEAT_HW_VLAN_CTAG_FILTER
,
32 NET_DEV_FEAT_HW_VLAN_STAG_TX
,
33 NET_DEV_FEAT_HW_VLAN_STAG_RX
,
34 NET_DEV_FEAT_HW_VLAN_STAG_FILTER
,
35 NET_DEV_FEAT_VLAN_CHALLENGED
,
38 NET_DEV_FEAT_NETNS_LOCAL
,
43 NET_DEV_FEAT_GSO_ROBUST
,
45 NET_DEV_FEAT_TSO_MANGLEID
,
49 NET_DEV_FEAT_GSO_GRE_CSUM
,
50 NET_DEV_FEAT_GSO_IPXIP4
,
51 NET_DEV_FEAT_GSO_IPXIP6
,
52 NET_DEV_FEAT_GSO_UDP_TUNNEL
,
53 NET_DEV_FEAT_GSO_UDP_TUNNEL_CSUM
,
54 NET_DEV_FEAT_GSO_PARTIAL
,
55 NET_DEV_FEAT_GSO_TUNNEL_REMCSUM
,
56 NET_DEV_FEAT_GSO_SCTP
,
58 NET_DEV_FEAT_GSO_UDP_L4
,
59 NET_DEV_FEAT_GSO_FRAGLIST
,
60 NET_DEV_FEAT_FCOE_CRC
,
61 NET_DEV_FEAT_SCTP_CRC
,
62 NET_DEV_FEAT_FCOE_MTU
,
66 NET_DEV_FEAT_NOCACHE_COPY
,
67 NET_DEV_FEAT_LOOPBACK
,
70 NET_DEV_FEAT_HW_L2FW_DOFFLOAD
,
73 NET_DEV_FEAT_HW_ESP_TX_CSUM
,
74 NET_DEV_FEAT_RX_UDP_TUNNEL_PORT
,
75 NET_DEV_FEAT_HW_TLS_RECORD
,
76 NET_DEV_FEAT_HW_TLS_TX
,
77 NET_DEV_FEAT_HW_TLS_RX
,
78 NET_DEV_FEAT_GRO_FRAGLIST
,
79 NET_DEV_FEAT_HW_MACSEC
,
80 NET_DEV_FEAT_GRO_UDP_FWD
,
81 NET_DEV_FEAT_HW_HSR_TAG_INS
,
82 NET_DEV_FEAT_HW_HSR_TAG_RM
,
83 NET_DEV_FEAT_HW_HSR_FWD
,
84 NET_DEV_FEAT_HW_HSR_DUP
,
85 _NET_DEV_FEAT_SIMPLE_MAX
,
87 NET_DEV_FEAT_TXCSUM
= _NET_DEV_FEAT_SIMPLE_MAX
,
89 _NET_DEV_FEAT_INVALID
= -EINVAL
,
92 typedef enum NetDevPort
{
93 NET_DEV_PORT_TP
= PORT_TP
,
94 NET_DEV_PORT_AUI
= PORT_AUI
,
95 NET_DEV_PORT_MII
= PORT_MII
,
96 NET_DEV_PORT_FIBRE
= PORT_FIBRE
,
97 NET_DEV_PORT_BNC
= PORT_BNC
,
98 NET_DEV_PORT_DA
= PORT_DA
,
99 NET_DEV_PORT_NONE
= PORT_NONE
,
100 NET_DEV_PORT_OTHER
= PORT_OTHER
,
102 _NET_DEV_PORT_INVALID
= -EINVAL
,
105 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
106 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
108 /* layout of the struct passed from/to userland */
109 struct ethtool_link_usettings
{
110 struct ethtool_link_settings base
;
113 uint32_t supported
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
114 uint32_t advertising
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
115 uint32_t lp_advertising
[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32
];
119 typedef struct u32_opt
{
120 uint32_t value
; /* a value of 0 indicates the hardware advertised maximum should be used. */
124 typedef struct netdev_channels
{
131 typedef struct netdev_ring_param
{
138 typedef struct netdev_coalesce_param
{
139 u32_opt rx_coalesce_usecs
;
140 u32_opt rx_max_coalesced_frames
;
141 u32_opt rx_coalesce_usecs_irq
;
142 u32_opt rx_max_coalesced_frames_irq
;
143 u32_opt tx_coalesce_usecs
;
144 u32_opt tx_max_coalesced_frames
;
145 u32_opt tx_coalesce_usecs_irq
;
146 u32_opt tx_max_coalesced_frames_irq
;
147 u32_opt stats_block_coalesce_usecs
;
148 int use_adaptive_rx_coalesce
;
149 int use_adaptive_tx_coalesce
;
150 u32_opt pkt_rate_low
;
151 u32_opt rx_coalesce_usecs_low
;
152 u32_opt rx_max_coalesced_frames_low
;
153 u32_opt tx_coalesce_usecs_low
;
154 u32_opt tx_max_coalesced_frames_low
;
155 u32_opt pkt_rate_high
;
156 u32_opt rx_coalesce_usecs_high
;
157 u32_opt rx_max_coalesced_frames_high
;
158 u32_opt tx_coalesce_usecs_high
;
159 u32_opt tx_max_coalesced_frames_high
;
160 u32_opt rate_sample_interval
;
161 } netdev_coalesce_param
;
163 int ethtool_get_driver(int *ethtool_fd
, const char *ifname
, char **ret
);
164 int ethtool_get_link_info(int *ethtool_fd
, const char *ifname
,
165 int *ret_autonegotiation
, uint64_t *ret_speed
,
166 Duplex
*ret_duplex
, NetDevPort
*ret_port
);
167 int ethtool_get_permanent_hw_addr(int *ethtool_fd
, const char *ifname
, struct hw_addr_data
*ret
);
168 int ethtool_set_wol(int *ethtool_fd
, const char *ifname
, uint32_t wolopts
, const uint8_t password
[SOPASS_MAX
]);
169 int ethtool_set_nic_buffer_size(int *ethtool_fd
, const char *ifname
, const netdev_ring_param
*ring
);
170 int ethtool_set_features(int *ethtool_fd
, const char *ifname
, const int features
[static _NET_DEV_FEAT_MAX
]);
171 int ethtool_set_glinksettings(
175 const uint32_t advertise
[static N_ADVERTISE
],
180 int ethtool_set_channels(int *ethtool_fd
, const char *ifname
, const netdev_channels
*channels
);
181 int ethtool_set_flow_control(int *fd
, const char *ifname
, int rx
, int tx
, int autoneg
);
182 int ethtool_set_nic_coalesce_settings(int *ethtool_fd
, const char *ifname
, const netdev_coalesce_param
*coalesce
);
184 const char *duplex_to_string(Duplex d
) _const_
;
185 Duplex
duplex_from_string(const char *d
) _pure_
;
187 int wol_options_to_string_alloc(uint32_t opts
, char **ret
);
189 const char *port_to_string(NetDevPort port
) _const_
;
190 NetDevPort
port_from_string(const char *port
) _pure_
;
192 const char *mdi_to_string(int mdi
) _const_
;
194 const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val
) _const_
;
195 enum ethtool_link_mode_bit_indices
ethtool_link_mode_bit_from_string(const char *str
) _pure_
;
197 CONFIG_PARSER_PROTOTYPE(config_parse_duplex
);
198 CONFIG_PARSER_PROTOTYPE(config_parse_wol
);
199 CONFIG_PARSER_PROTOTYPE(config_parse_port
);
200 CONFIG_PARSER_PROTOTYPE(config_parse_mdi
);
201 CONFIG_PARSER_PROTOTYPE(config_parse_advertise
);
202 CONFIG_PARSER_PROTOTYPE(config_parse_ring_buffer_or_channel
);
203 CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_u32
);
204 CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_sec
);
205 CONFIG_PARSER_PROTOTYPE(config_parse_nic_coalesce_setting
);