]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/net/ethtool-util.h
Merge pull request #10159 from poettering/killall-spree-kernel-thread
[thirdparty/systemd.git] / src / udev / net / ethtool-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <macro.h>
5 #include <linux/ethtool.h>
6
7 #include "missing.h"
8
9 struct link_config;
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 = -1
18 } Duplex;
19
20 typedef enum WakeOnLan {
21 WOL_PHY,
22 WOL_UCAST,
23 WOL_MCAST,
24 WOL_BCAST,
25 WOL_ARP,
26 WOL_MAGIC,
27 WOL_MAGICSECURE,
28 WOL_OFF,
29 _WOL_MAX,
30 _WOL_INVALID = -1
31 } WakeOnLan;
32
33 typedef enum NetDevFeature {
34 NET_DEV_FEAT_GSO,
35 NET_DEV_FEAT_GRO,
36 NET_DEV_FEAT_LRO,
37 NET_DEV_FEAT_TSO,
38 NET_DEV_FEAT_TSO6,
39 _NET_DEV_FEAT_MAX,
40 _NET_DEV_FEAT_INVALID = -1
41 } NetDevFeature;
42
43 typedef enum NetDevPort {
44 NET_DEV_PORT_TP = 0x00,
45 NET_DEV_PORT_AUI = 0x01,
46 NET_DEV_PORT_MII = 0x02,
47 NET_DEV_PORT_FIBRE = 0x03,
48 NET_DEV_PORT_BNC = 0x04,
49 NET_DEV_PORT_DA = 0x05,
50 NET_DEV_PORT_NONE = 0xef,
51 NET_DEV_PORT_OTHER = 0xff,
52 _NET_DEV_PORT_MAX,
53 _NET_DEV_PORT_INVALID = -1
54 } NetDevPort;
55
56 typedef enum NetDevAdvertise {
57 NET_DEV_ADVERTISE_10BASET_HALF = 1 << ETHTOOL_LINK_MODE_10baseT_Half_BIT,
58 NET_DEV_ADVERTISE_10BASET_FULL = 1 << ETHTOOL_LINK_MODE_10baseT_Full_BIT,
59 NET_DEV_ADVERTISE_100BASET_HALF = 1 << ETHTOOL_LINK_MODE_100baseT_Half_BIT,
60 NET_DEV_ADVERTISE_100BASET_FULL = 1 << ETHTOOL_LINK_MODE_100baseT_Full_BIT,
61 NET_DEV_ADVERTISE_1000BASET_HALF = 1 << ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
62 NET_DEV_ADVERTISE_1000BASET_FULL = 1 << ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
63 NET_DEV_ADVERTISE_10000BASET_FULL = 1 << ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
64 NET_DEV_ADVERTISE_2500BASEX_FULL = 1 << ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
65 NET_DEV_ADVERTISE_1000BASEKX_FULL = 1 << ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
66 NET_DEV_ADVERTISE_10000BASEKX4_FULL = 1 << ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
67 NET_DEV_ADVERTISE_10000BASEKR_FULL = 1 << ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
68 NET_DEV_ADVERTISE_10000BASER_FEC = 1 << ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
69 NET_DEV_ADVERTISE_20000BASEMLD2_Full = 1 << ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
70 NET_DEV_ADVERTISE_20000BASEKR2_Full = 1 << ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
71 _NET_DEV_ADVERTISE_MAX,
72 _NET_DEV_ADVERTISE_INVALID = -1,
73 } NetDevAdvertise;
74
75 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
76 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
77
78 /* layout of the struct passed from/to userland */
79 struct ethtool_link_usettings {
80 struct ethtool_link_settings base;
81
82 struct {
83 uint32_t supported[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
84 uint32_t advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
85 uint32_t lp_advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
86 } link_modes;
87 };
88
89 typedef struct netdev_channels {
90 uint32_t rx_count;
91 uint32_t tx_count;
92 uint32_t other_count;
93 uint32_t combined_count;
94
95 bool rx_count_set;
96 bool tx_count_set;
97 bool other_count_set;
98 bool combined_count_set;
99 } netdev_channels;
100
101 int ethtool_connect(int *ret);
102
103 int ethtool_get_driver(int *fd, const char *ifname, char **ret);
104 int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex);
105 int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
106 int ethtool_set_features(int *fd, const char *ifname, int *features);
107 int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *link);
108 int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels);
109
110 const char *duplex_to_string(Duplex d) _const_;
111 Duplex duplex_from_string(const char *d) _pure_;
112
113 const char *wol_to_string(WakeOnLan wol) _const_;
114 WakeOnLan wol_from_string(const char *wol) _pure_;
115
116 const char *port_to_string(NetDevPort port) _const_;
117 NetDevPort port_from_string(const char *port) _pure_;
118
119 const char *advertise_to_string(NetDevAdvertise advertise) _const_;
120 NetDevAdvertise advertise_from_string(const char *advertise) _pure_;
121
122 int config_parse_duplex(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
123 int config_parse_wol(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
124 int config_parse_port(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
125 int config_parse_channel(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
126 int config_parse_advertise(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);