]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
0ef6f454 LP |
2 | #pragma once |
3 | ||
5fde13d7 | 4 | #include <macro.h> |
79b4428a | 5 | #include <net/ethernet.h> |
a39f92d3 SS |
6 | #include <linux/ethtool.h> |
7 | ||
538f15cf | 8 | #include "conf-parser.h" |
ed9fa69f | 9 | #include "ether-addr-util.h" |
5fde13d7 | 10 | |
72dda93a | 11 | #define N_ADVERTISE 3 |
593022fa | 12 | |
5fde13d7 TG |
13 | /* we can't use DUPLEX_ prefix, as it |
14 | * clashes with <linux/ethtool.h> */ | |
15 | typedef enum Duplex { | |
9432a05c SS |
16 | DUP_HALF = DUPLEX_HALF, |
17 | DUP_FULL = DUPLEX_FULL, | |
5fde13d7 | 18 | _DUP_MAX, |
2d93c20e | 19 | _DUP_INVALID = -EINVAL, |
5fde13d7 TG |
20 | } Duplex; |
21 | ||
50725d10 | 22 | typedef enum NetDevFeature { |
77bf5c31 YW |
23 | NET_DEV_FEAT_SG, |
24 | NET_DEV_FEAT_IP_CSUM, | |
25 | NET_DEV_FEAT_HW_CSUM, | |
26 | NET_DEV_FEAT_IPV6_CSUM, | |
27 | NET_DEV_FEAT_HIGHDMA, | |
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, | |
50725d10 | 36 | NET_DEV_FEAT_GSO, |
77bf5c31 YW |
37 | NET_DEV_FEAT_LLTX, |
38 | NET_DEV_FEAT_NETNS_LOCAL, | |
f7ea90fb | 39 | NET_DEV_FEAT_GRO, |
8f821d90 | 40 | NET_DEV_FEAT_GRO_HW, |
f7ea90fb | 41 | NET_DEV_FEAT_LRO, |
50725d10 | 42 | NET_DEV_FEAT_TSO, |
77bf5c31 YW |
43 | NET_DEV_FEAT_GSO_ROBUST, |
44 | NET_DEV_FEAT_TSO_ECN, | |
45 | NET_DEV_FEAT_TSO_MANGLEID, | |
ffa69a04 | 46 | NET_DEV_FEAT_TSO6, |
77bf5c31 YW |
47 | NET_DEV_FEAT_FSO, |
48 | NET_DEV_FEAT_GSO_GRE, | |
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, | |
57 | NET_DEV_FEAT_GSO_ESP, | |
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, | |
63 | NET_DEV_FEAT_NTUPLE, | |
64 | NET_DEV_FEAT_RXHASH, | |
65 | NET_DEV_FEAT_RXCSUM, | |
66 | NET_DEV_FEAT_NOCACHE_COPY, | |
67 | NET_DEV_FEAT_LOOPBACK, | |
68 | NET_DEV_FEAT_RXFCS, | |
69 | NET_DEV_FEAT_RXALL, | |
70 | NET_DEV_FEAT_HW_L2FW_DOFFLOAD, | |
71 | NET_DEV_FEAT_HW_TC, | |
72 | NET_DEV_FEAT_HW_ESP, | |
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, | |
7a4f2035 YW |
85 | _NET_DEV_FEAT_SIMPLE_MAX, |
86 | ||
77bf5c31 | 87 | NET_DEV_FEAT_TXCSUM = _NET_DEV_FEAT_SIMPLE_MAX, |
50725d10 | 88 | _NET_DEV_FEAT_MAX, |
2d93c20e | 89 | _NET_DEV_FEAT_INVALID = -EINVAL, |
50725d10 SS |
90 | } NetDevFeature; |
91 | ||
593022fa | 92 | typedef enum NetDevPort { |
1637c357 YW |
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, | |
593022fa | 101 | _NET_DEV_PORT_MAX, |
2d93c20e | 102 | _NET_DEV_PORT_INVALID = -EINVAL, |
593022fa | 103 | } NetDevPort; |
a39f92d3 SS |
104 | |
105 | #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX) | |
6cf0a204 | 106 | #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) |
a39f92d3 SS |
107 | |
108 | /* layout of the struct passed from/to userland */ | |
109 | struct ethtool_link_usettings { | |
110 | struct ethtool_link_settings base; | |
111 | ||
112 | struct { | |
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]; | |
116 | } link_modes; | |
117 | }; | |
118 | ||
0d341ecc YW |
119 | typedef struct u32_opt { |
120 | uint32_t value; /* a value of 0 indicates the hardware advertised maximum should be used.*/ | |
121 | bool set; | |
122 | } u32_opt; | |
123 | ||
5f945202 | 124 | typedef struct netdev_channels { |
0d341ecc YW |
125 | u32_opt rx; |
126 | u32_opt tx; | |
127 | u32_opt other; | |
128 | u32_opt combined; | |
5f945202 SS |
129 | } netdev_channels; |
130 | ||
224ded67 | 131 | typedef struct netdev_ring_param { |
0d341ecc YW |
132 | u32_opt rx; |
133 | u32_opt rx_mini; | |
134 | u32_opt rx_jumbo; | |
135 | u32_opt tx; | |
224ded67 SS |
136 | } netdev_ring_param; |
137 | ||
6c35ea5e DDM |
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; | |
162 | ||
64be35ab ZJS |
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, | |
50299121 | 165 | int *ret_autonegotiation, uint64_t *ret_speed, |
33a8695f | 166 | Duplex *ret_duplex, NetDevPort *ret_port); |
ed9fa69f | 167 | int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret); |
9bd3ecdd | 168 | int ethtool_set_wol(int *ethtool_fd, const char *ifname, uint32_t wolopts, const uint8_t password[SOPASS_MAX]); |
cadc7ed2 | 169 | int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring); |
0db68800 | 170 | int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]); |
18f84f8a YW |
171 | int ethtool_set_glinksettings( |
172 | int *fd, | |
173 | const char *ifname, | |
174 | int autonegotiation, | |
175 | const uint32_t advertise[static N_ADVERTISE], | |
176 | uint64_t speed, | |
177 | Duplex duplex, | |
178 | NetDevPort port, | |
179 | uint8_t mdi); | |
cadc7ed2 | 180 | int ethtool_set_channels(int *ethtool_fd, const char *ifname, const netdev_channels *channels); |
a34811e4 | 181 | int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg); |
6c35ea5e | 182 | int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce); |
5fde13d7 TG |
183 | |
184 | const char *duplex_to_string(Duplex d) _const_; | |
185 | Duplex duplex_from_string(const char *d) _pure_; | |
186 | ||
c50404ae | 187 | int wol_options_to_string_alloc(uint32_t opts, char **ret); |
5fde13d7 | 188 | |
593022fa SS |
189 | const char *port_to_string(NetDevPort port) _const_; |
190 | NetDevPort port_from_string(const char *port) _pure_; | |
191 | ||
18f84f8a YW |
192 | const char *mdi_to_string(int mdi) _const_; |
193 | ||
2d18ac44 YW |
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_; | |
6cf0a204 | 196 | |
538f15cf YW |
197 | CONFIG_PARSER_PROTOTYPE(config_parse_duplex); |
198 | CONFIG_PARSER_PROTOTYPE(config_parse_wol); | |
199 | CONFIG_PARSER_PROTOTYPE(config_parse_port); | |
18f84f8a | 200 | CONFIG_PARSER_PROTOTYPE(config_parse_mdi); |
538f15cf | 201 | CONFIG_PARSER_PROTOTYPE(config_parse_advertise); |
0d341ecc | 202 | CONFIG_PARSER_PROTOTYPE(config_parse_ring_buffer_or_channel); |
6c35ea5e DDM |
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); |