]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/ethtool-util.h
udev: Add support for configuring nic coalescing settings
[thirdparty/systemd.git] / src / shared / ethtool-util.h
CommitLineData
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"
5fde13d7 9
72dda93a 10#define N_ADVERTISE 3
593022fa 11
5fde13d7
TG
12/* we can't use DUPLEX_ prefix, as it
13 * clashes with <linux/ethtool.h> */
14typedef enum Duplex {
9432a05c
SS
15 DUP_HALF = DUPLEX_HALF,
16 DUP_FULL = DUPLEX_FULL,
5fde13d7 17 _DUP_MAX,
2d93c20e 18 _DUP_INVALID = -EINVAL,
5fde13d7
TG
19} Duplex;
20
50725d10 21typedef enum NetDevFeature {
bf2334c0
YW
22 NET_DEV_FEAT_RX,
23 NET_DEV_FEAT_TX,
50725d10 24 NET_DEV_FEAT_GSO,
f7ea90fb
SS
25 NET_DEV_FEAT_GRO,
26 NET_DEV_FEAT_LRO,
50725d10 27 NET_DEV_FEAT_TSO,
ffa69a04 28 NET_DEV_FEAT_TSO6,
50725d10 29 _NET_DEV_FEAT_MAX,
2d93c20e 30 _NET_DEV_FEAT_INVALID = -EINVAL,
50725d10
SS
31} NetDevFeature;
32
593022fa 33typedef enum NetDevPort {
1637c357
YW
34 NET_DEV_PORT_TP = PORT_TP,
35 NET_DEV_PORT_AUI = PORT_AUI,
36 NET_DEV_PORT_MII = PORT_MII,
37 NET_DEV_PORT_FIBRE = PORT_FIBRE,
38 NET_DEV_PORT_BNC = PORT_BNC,
39 NET_DEV_PORT_DA = PORT_DA,
40 NET_DEV_PORT_NONE = PORT_NONE,
41 NET_DEV_PORT_OTHER = PORT_OTHER,
593022fa 42 _NET_DEV_PORT_MAX,
2d93c20e 43 _NET_DEV_PORT_INVALID = -EINVAL,
593022fa 44} NetDevPort;
a39f92d3
SS
45
46#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
6cf0a204 47#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
a39f92d3
SS
48
49/* layout of the struct passed from/to userland */
50struct ethtool_link_usettings {
51 struct ethtool_link_settings base;
52
53 struct {
54 uint32_t supported[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
55 uint32_t advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
56 uint32_t lp_advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
57 } link_modes;
58};
59
0d341ecc
YW
60typedef struct u32_opt {
61 uint32_t value; /* a value of 0 indicates the hardware advertised maximum should be used.*/
62 bool set;
63} u32_opt;
64
5f945202 65typedef struct netdev_channels {
0d341ecc
YW
66 u32_opt rx;
67 u32_opt tx;
68 u32_opt other;
69 u32_opt combined;
5f945202
SS
70} netdev_channels;
71
224ded67 72typedef struct netdev_ring_param {
0d341ecc
YW
73 u32_opt rx;
74 u32_opt rx_mini;
75 u32_opt rx_jumbo;
76 u32_opt tx;
224ded67
SS
77} netdev_ring_param;
78
6c35ea5e
DDM
79typedef struct netdev_coalesce_param {
80 u32_opt rx_coalesce_usecs;
81 u32_opt rx_max_coalesced_frames;
82 u32_opt rx_coalesce_usecs_irq;
83 u32_opt rx_max_coalesced_frames_irq;
84 u32_opt tx_coalesce_usecs;
85 u32_opt tx_max_coalesced_frames;
86 u32_opt tx_coalesce_usecs_irq;
87 u32_opt tx_max_coalesced_frames_irq;
88 u32_opt stats_block_coalesce_usecs;
89 int use_adaptive_rx_coalesce;
90 int use_adaptive_tx_coalesce;
91 u32_opt pkt_rate_low;
92 u32_opt rx_coalesce_usecs_low;
93 u32_opt rx_max_coalesced_frames_low;
94 u32_opt tx_coalesce_usecs_low;
95 u32_opt tx_max_coalesced_frames_low;
96 u32_opt pkt_rate_high;
97 u32_opt rx_coalesce_usecs_high;
98 u32_opt rx_max_coalesced_frames_high;
99 u32_opt tx_coalesce_usecs_high;
100 u32_opt tx_max_coalesced_frames_high;
101 u32_opt rate_sample_interval;
102} netdev_coalesce_param;
103
64be35ab
ZJS
104int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
105int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
50299121 106 int *ret_autonegotiation, uint64_t *ret_speed,
33a8695f 107 Duplex *ret_duplex, NetDevPort *ret_port);
64be35ab 108int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
c50404ae 109int ethtool_set_wol(int *ethtool_fd, const char *ifname, uint32_t wolopts);
cadc7ed2 110int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring);
0db68800 111int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]);
64be35ab 112int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
cadc7ed2 113 int autonegotiation, const uint32_t advertise[static N_ADVERTISE],
50299121 114 uint64_t speed, Duplex duplex, NetDevPort port);
cadc7ed2 115int ethtool_set_channels(int *ethtool_fd, const char *ifname, const netdev_channels *channels);
a34811e4 116int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg);
6c35ea5e 117int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce);
5fde13d7
TG
118
119const char *duplex_to_string(Duplex d) _const_;
120Duplex duplex_from_string(const char *d) _pure_;
121
c50404ae 122int wol_options_to_string_alloc(uint32_t opts, char **ret);
5fde13d7 123
593022fa
SS
124const char *port_to_string(NetDevPort port) _const_;
125NetDevPort port_from_string(const char *port) _pure_;
126
2d18ac44
YW
127const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val) _const_;
128enum ethtool_link_mode_bit_indices ethtool_link_mode_bit_from_string(const char *str) _pure_;
6cf0a204 129
538f15cf
YW
130CONFIG_PARSER_PROTOTYPE(config_parse_duplex);
131CONFIG_PARSER_PROTOTYPE(config_parse_wol);
132CONFIG_PARSER_PROTOTYPE(config_parse_port);
538f15cf 133CONFIG_PARSER_PROTOTYPE(config_parse_advertise);
0d341ecc 134CONFIG_PARSER_PROTOTYPE(config_parse_ring_buffer_or_channel);
6c35ea5e
DDM
135CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_u32);
136CONFIG_PARSER_PROTOTYPE(config_parse_coalesce_sec);
137CONFIG_PARSER_PROTOTYPE(config_parse_nic_coalesce_setting);