]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/ethtool-util.h
Merge pull request #16491 from keszybz/udev-logging
[thirdparty/systemd.git] / src / shared / ethtool-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
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
TG
17 _DUP_MAX,
18 _DUP_INVALID = -1
19} Duplex;
20
21typedef enum WakeOnLan {
22 WOL_PHY,
617da14c
SS
23 WOL_UCAST,
24 WOL_MCAST,
25 WOL_BCAST,
26 WOL_ARP,
5fde13d7 27 WOL_MAGIC,
617da14c 28 WOL_MAGICSECURE,
5fde13d7
TG
29 WOL_OFF,
30 _WOL_MAX,
31 _WOL_INVALID = -1
32} WakeOnLan;
33
50725d10 34typedef enum NetDevFeature {
bf2334c0
YW
35 NET_DEV_FEAT_RX,
36 NET_DEV_FEAT_TX,
50725d10 37 NET_DEV_FEAT_GSO,
f7ea90fb
SS
38 NET_DEV_FEAT_GRO,
39 NET_DEV_FEAT_LRO,
50725d10 40 NET_DEV_FEAT_TSO,
ffa69a04 41 NET_DEV_FEAT_TSO6,
50725d10
SS
42 _NET_DEV_FEAT_MAX,
43 _NET_DEV_FEAT_INVALID = -1
44} NetDevFeature;
45
593022fa 46typedef enum NetDevPort {
1637c357
YW
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,
593022fa
SS
55 _NET_DEV_PORT_MAX,
56 _NET_DEV_PORT_INVALID = -1
57} NetDevPort;
a39f92d3
SS
58
59#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
6cf0a204 60#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
a39f92d3
SS
61
62/* layout of the struct passed from/to userland */
63struct ethtool_link_usettings {
64 struct ethtool_link_settings base;
65
66 struct {
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];
70 } link_modes;
71};
72
5f945202
SS
73typedef struct netdev_channels {
74 uint32_t rx_count;
75 uint32_t tx_count;
76 uint32_t other_count;
77 uint32_t combined_count;
78
79 bool rx_count_set;
80 bool tx_count_set;
81 bool other_count_set;
82 bool combined_count_set;
83} netdev_channels;
84
224ded67
SS
85typedef struct netdev_ring_param {
86 uint32_t rx_pending;
e81f5fc4 87 uint32_t rx_mini_pending;
88 uint32_t rx_jumbo_pending;
224ded67
SS
89 uint32_t tx_pending;
90
91 bool rx_pending_set;
e81f5fc4 92 bool rx_mini_pending_set;
93 bool rx_jumbo_pending_set;
224ded67
SS
94 bool tx_pending_set;
95} netdev_ring_param;
96
64be35ab
ZJS
97int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
98int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
50299121 99 int *ret_autonegotiation, uint64_t *ret_speed,
33a8695f 100 Duplex *ret_duplex, NetDevPort *ret_port);
64be35ab
ZJS
101int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
102int ethtool_set_speed(int *ethtool_fd, const char *ifname, unsigned speed, Duplex duplex);
103int ethtool_set_wol(int *ethtool_fd, const char *ifname, WakeOnLan wol);
104int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, netdev_ring_param *ring);
105int ethtool_set_features(int *ethtool_fd, const char *ifname, int *features);
106int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
5c2316c6 107 int autonegotiation, uint32_t advertise[static N_ADVERTISE],
50299121 108 uint64_t speed, Duplex duplex, NetDevPort port);
64be35ab 109int ethtool_set_channels(int *ethtool_fd, const char *ifname, netdev_channels *channels);
a34811e4 110int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg);
5fde13d7
TG
111
112const char *duplex_to_string(Duplex d) _const_;
113Duplex duplex_from_string(const char *d) _pure_;
114
115const char *wol_to_string(WakeOnLan wol) _const_;
116WakeOnLan wol_from_string(const char *wol) _pure_;
117
593022fa
SS
118const char *port_to_string(NetDevPort port) _const_;
119NetDevPort port_from_string(const char *port) _pure_;
120
2d18ac44
YW
121const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val) _const_;
122enum ethtool_link_mode_bit_indices ethtool_link_mode_bit_from_string(const char *str) _pure_;
6cf0a204 123
538f15cf
YW
124CONFIG_PARSER_PROTOTYPE(config_parse_duplex);
125CONFIG_PARSER_PROTOTYPE(config_parse_wol);
126CONFIG_PARSER_PROTOTYPE(config_parse_port);
127CONFIG_PARSER_PROTOTYPE(config_parse_channel);
128CONFIG_PARSER_PROTOTYPE(config_parse_advertise);
224ded67 129CONFIG_PARSER_PROTOTYPE(config_parse_nic_buffer_size);