| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <linux/ethtool.h> |
| 5 |
|
| 6 |
#include "conf-parser-forward.h" |
| 7 |
#include "shared-forward.h" |
| 8 |
|
| 9 |
#define N_ADVERTISE 4 |
| 10 |
|
| 11 |
/* we can't use DUPLEX_ prefix, as it |
| 12 |
* clashes with <linux/ethtool.h> */ |
| 13 |
typedef enum Duplex { |
| 14 |
DUP_HALF = DUPLEX_HALF, |
| 15 |
DUP_FULL = DUPLEX_FULL, |
| 16 |
_DUP_MAX, |
| 17 |
_DUP_INVALID = -EINVAL, |
| 18 |
} Duplex; |
| 19 |
|
| 20 |
typedef enum NetDevFeature { |
| 21 |
NET_DEV_FEAT_SG, |
| 22 |
NET_DEV_FEAT_IP_CSUM, |
| 23 |
NET_DEV_FEAT_HW_CSUM, |
| 24 |
NET_DEV_FEAT_IPV6_CSUM, |
| 25 |
NET_DEV_FEAT_HIGHDMA, |
| 26 |
NET_DEV_FEAT_FRAGLIST, |
| 27 |
NET_DEV_FEAT_HW_VLAN_CTAG_TX, |
| 28 |
NET_DEV_FEAT_HW_VLAN_CTAG_RX, |
| 29 |
NET_DEV_FEAT_HW_VLAN_CTAG_FILTER, |
| 30 |
NET_DEV_FEAT_HW_VLAN_STAG_TX, |
| 31 |
NET_DEV_FEAT_HW_VLAN_STAG_RX, |
| 32 |
NET_DEV_FEAT_HW_VLAN_STAG_FILTER, |
| 33 |
NET_DEV_FEAT_VLAN_CHALLENGED, |
| 34 |
NET_DEV_FEAT_GSO, |
| 35 |
NET_DEV_FEAT_LLTX, |
| 36 |
NET_DEV_FEAT_NETNS_LOCAL, |
| 37 |
NET_DEV_FEAT_GRO, |
| 38 |
NET_DEV_FEAT_GRO_HW, |
| 39 |
NET_DEV_FEAT_LRO, |
| 40 |
NET_DEV_FEAT_TSO, |
| 41 |
NET_DEV_FEAT_GSO_ROBUST, |
| 42 |
NET_DEV_FEAT_TSO_ECN, |
| 43 |
NET_DEV_FEAT_TSO_MANGLEID, |
| 44 |
NET_DEV_FEAT_TSO6, |
| 45 |
NET_DEV_FEAT_FSO, |
| 46 |
NET_DEV_FEAT_GSO_GRE, |
| 47 |
NET_DEV_FEAT_GSO_GRE_CSUM, |
| 48 |
NET_DEV_FEAT_GSO_IPXIP4, |
| 49 |
NET_DEV_FEAT_GSO_IPXIP6, |
| 50 |
NET_DEV_FEAT_GSO_UDP_TUNNEL, |
| 51 |
NET_DEV_FEAT_GSO_UDP_TUNNEL_CSUM, |
| 52 |
NET_DEV_FEAT_GSO_PARTIAL, |
| 53 |
NET_DEV_FEAT_GSO_TUNNEL_REMCSUM, |
| 54 |
NET_DEV_FEAT_GSO_SCTP, |
| 55 |
NET_DEV_FEAT_GSO_ESP, |
| 56 |
NET_DEV_FEAT_GSO_UDP_L4, |
| 57 |
NET_DEV_FEAT_GSO_FRAGLIST, |
| 58 |
NET_DEV_FEAT_FCOE_CRC, |
| 59 |
NET_DEV_FEAT_SCTP_CRC, |
| 60 |
NET_DEV_FEAT_FCOE_MTU, |
| 61 |
NET_DEV_FEAT_NTUPLE, |
| 62 |
NET_DEV_FEAT_RXHASH, |
| 63 |
NET_DEV_FEAT_RXCSUM, |
| 64 |
NET_DEV_FEAT_NOCACHE_COPY, |
| 65 |
NET_DEV_FEAT_LOOPBACK, |
| 66 |
NET_DEV_FEAT_RXFCS, |
| 67 |
NET_DEV_FEAT_RXALL, |
| 68 |
NET_DEV_FEAT_HW_L2FW_DOFFLOAD, |
| 69 |
NET_DEV_FEAT_HW_TC, |
| 70 |
NET_DEV_FEAT_HW_ESP, |
| 71 |
NET_DEV_FEAT_HW_ESP_TX_CSUM, |
| 72 |
NET_DEV_FEAT_RX_UDP_TUNNEL_PORT, |
| 73 |
NET_DEV_FEAT_HW_TLS_RECORD, |
| 74 |
NET_DEV_FEAT_HW_TLS_TX, |
| 75 |
NET_DEV_FEAT_HW_TLS_RX, |
| 76 |
NET_DEV_FEAT_GRO_FRAGLIST, |
| 77 |
NET_DEV_FEAT_HW_MACSEC, |
| 78 |
NET_DEV_FEAT_GRO_UDP_FWD, |
| 79 |
NET_DEV_FEAT_HW_HSR_TAG_INS, |
| 80 |
NET_DEV_FEAT_HW_HSR_TAG_RM, |
| 81 |
NET_DEV_FEAT_HW_HSR_FWD, |
| 82 |
NET_DEV_FEAT_HW_HSR_DUP, |
| 83 |
_NET_DEV_FEAT_SIMPLE_MAX, |
| 84 |
|
| 85 |
NET_DEV_FEAT_TXCSUM = _NET_DEV_FEAT_SIMPLE_MAX, |
| 86 |
_NET_DEV_FEAT_MAX, |
| 87 |
_NET_DEV_FEAT_INVALID = -EINVAL, |
| 88 |
} NetDevFeature; |
| 89 |
|
| 90 |
typedef enum NetDevPort { |
| 91 |
NET_DEV_PORT_TP = PORT_TP, |
| 92 |
NET_DEV_PORT_AUI = PORT_AUI, |
| 93 |
NET_DEV_PORT_MII = PORT_MII, |
| 94 |
NET_DEV_PORT_FIBRE = PORT_FIBRE, |
| 95 |
NET_DEV_PORT_BNC = PORT_BNC, |
| 96 |
NET_DEV_PORT_DA = PORT_DA, |
| 97 |
NET_DEV_PORT_NONE = PORT_NONE, |
| 98 |
NET_DEV_PORT_OTHER = PORT_OTHER, |
| 99 |
_NET_DEV_PORT_MAX, |
| 100 |
_NET_DEV_PORT_INVALID = -EINVAL, |
| 101 |
} NetDevPort; |
| 102 |
|
| 103 |
typedef struct u32_opt { |
| 104 |
uint32_t value; /* a value of 0 indicates the hardware advertised maximum should be used. */ |
| 105 |
bool set; |
| 106 |
} u32_opt; |
| 107 |
|
| 108 |
typedef struct netdev_channels { |
| 109 |
u32_opt rx; |
| 110 |
u32_opt tx; |
| 111 |
u32_opt other; |
| 112 |
u32_opt combined; |
| 113 |
} netdev_channels; |
| 114 |
|
| 115 |
typedef struct netdev_ring_param { |
| 116 |
u32_opt rx; |
| 117 |
u32_opt rx_mini; |
| 118 |
u32_opt rx_jumbo; |
| 119 |
u32_opt tx; |
| 120 |
} netdev_ring_param; |
| 121 |
|
| 122 |
typedef struct netdev_coalesce_param { |
| 123 |
u32_opt rx_coalesce_usecs; |
| 124 |
u32_opt rx_max_coalesced_frames; |
| 125 |
u32_opt rx_coalesce_usecs_irq; |
| 126 |
u32_opt rx_max_coalesced_frames_irq; |
| 127 |
u32_opt tx_coalesce_usecs; |
| 128 |
u32_opt tx_max_coalesced_frames; |
| 129 |
u32_opt tx_coalesce_usecs_irq; |
| 130 |
u32_opt tx_max_coalesced_frames_irq; |
| 131 |
u32_opt stats_block_coalesce_usecs; |
| 132 |
int use_adaptive_rx_coalesce; |
| 133 |
int use_adaptive_tx_coalesce; |
| 134 |
u32_opt pkt_rate_low; |
| 135 |
u32_opt rx_coalesce_usecs_low; |
| 136 |
u32_opt rx_max_coalesced_frames_low; |
| 137 |
u32_opt tx_coalesce_usecs_low; |
| 138 |
u32_opt tx_max_coalesced_frames_low; |
| 139 |
u32_opt pkt_rate_high; |
| 140 |
u32_opt rx_coalesce_usecs_high; |
| 141 |
u32_opt rx_max_coalesced_frames_high; |
| 142 |
u32_opt tx_coalesce_usecs_high; |
| 143 |
u32_opt tx_max_coalesced_frames_high; |
| 144 |
u32_opt rate_sample_interval; |
| 145 |
} netdev_coalesce_param; |
| 146 |
|
| 147 |
int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret); |
| 148 |
int ethtool_get_link_info(int *ethtool_fd, const char *ifname, |
| 149 |
int *ret_autonegotiation, uint64_t *ret_speed, |
| 150 |
Duplex *ret_duplex, NetDevPort *ret_port); |
| 151 |
int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret); |
| 152 |
int ethtool_set_wol(int *ethtool_fd, const char *ifname, uint32_t wolopts, const uint8_t password[SOPASS_MAX]); |
| 153 |
int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring); |
| 154 |
int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]); |
| 155 |
int ethtool_set_link_settings( |
| 156 |
int *fd, |
| 157 |
const char *ifname, |
| 158 |
int autonegotiation, |
| 159 |
const uint32_t advertise[static N_ADVERTISE], |
| 160 |
uint64_t speed, |
| 161 |
Duplex duplex, |
| 162 |
NetDevPort port, |
| 163 |
uint8_t mdi); |
| 164 |
int ethtool_set_channels(int *ethtool_fd, const char *ifname, const netdev_channels *channels); |
| 165 |
int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg); |
| 166 |
int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce); |
| 167 |
int ethtool_set_eee_settings( |
| 168 |
int *ethtool_fd, |
| 169 |
const char *ifname, |
| 170 |
int enabled, |
| 171 |
int tx_lpi_enabled, |
| 172 |
usec_t tx_lpi_timer_usec, |
| 173 |
uint32_t advertise); |
| 174 |
|
| 175 |
DECLARE_STRING_TABLE_LOOKUP(duplex, Duplex); |
| 176 |
|
| 177 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(wol_options, uint32_t); |
| 178 |
|
| 179 |
DECLARE_STRING_TABLE_LOOKUP(port, NetDevPort); |
| 180 |
|
| 181 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(mdi, int); |
| 182 |
|
| 183 |
DECLARE_STRING_TABLE_LOOKUP(ethtool_link_mode_bit, enum ethtool_link_mode_bit_indices); |
| 184 |
|
| 185 |
CONFIG_PARSER_PROTOTYPE(config_parse_duplex); |
| 186 |
CONFIG_PARSER_PROTOTYPE(config_parse_wol); |
| 187 |
CONFIG_PARSER_PROTOTYPE(config_parse_port); |
| 188 |
CONFIG_PARSER_PROTOTYPE(config_parse_mdi); |
| 189 |
CONFIG_PARSER_PROTOTYPE(config_parse_advertise); |
| 190 |
CONFIG_PARSER_PROTOTYPE(config_parse_ring_buffer_or_channel); |
| 191 |
CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_u32); |
| 192 |
CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_sec); |
| 193 |
CONFIG_PARSER_PROTOTYPE(config_parse_nic_coalesce_setting); |