]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/net/ethtool-util.h
8371533cc9e4f57e7f24825607d26cc5d98bd929
[thirdparty/systemd.git] / src / udev / net / ethtool-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
6 ***/
7
8 #include <macro.h>
9 #include <linux/ethtool.h>
10
11 #include "missing.h"
12
13 struct link_config;
14
15 /* we can't use DUPLEX_ prefix, as it
16 * clashes with <linux/ethtool.h> */
17 typedef enum Duplex {
18 DUP_HALF = DUPLEX_HALF,
19 DUP_FULL = DUPLEX_FULL,
20 _DUP_MAX,
21 _DUP_INVALID = -1
22 } Duplex;
23
24 typedef enum WakeOnLan {
25 WOL_PHY,
26 WOL_UCAST,
27 WOL_MCAST,
28 WOL_BCAST,
29 WOL_ARP,
30 WOL_MAGIC,
31 WOL_MAGICSECURE,
32 WOL_OFF,
33 _WOL_MAX,
34 _WOL_INVALID = -1
35 } WakeOnLan;
36
37 typedef enum NetDevFeature {
38 NET_DEV_FEAT_GSO,
39 NET_DEV_FEAT_GRO,
40 NET_DEV_FEAT_LRO,
41 NET_DEV_FEAT_TSO,
42 NET_DEV_FEAT_TSO6,
43 _NET_DEV_FEAT_MAX,
44 _NET_DEV_FEAT_INVALID = -1
45 } NetDevFeature;
46
47 typedef enum NetDevPort {
48 NET_DEV_PORT_TP = 0x00,
49 NET_DEV_PORT_AUI = 0x01,
50 NET_DEV_PORT_MII = 0x02,
51 NET_DEV_PORT_FIBRE = 0x03,
52 NET_DEV_PORT_BNC = 0x04,
53 NET_DEV_PORT_DA = 0x05,
54 NET_DEV_PORT_NONE = 0xef,
55 NET_DEV_PORT_OTHER = 0xff,
56 _NET_DEV_PORT_MAX,
57 _NET_DEV_PORT_INVALID = -1
58 } NetDevPort;
59
60 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
61
62 /* layout of the struct passed from/to userland */
63 struct 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
73 typedef 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
85 int ethtool_connect(int *ret);
86
87 int ethtool_get_driver(int *fd, const char *ifname, char **ret);
88 int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex);
89 int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
90 int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features);
91 int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *link);
92 int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels);
93
94 const char *duplex_to_string(Duplex d) _const_;
95 Duplex duplex_from_string(const char *d) _pure_;
96
97 const char *wol_to_string(WakeOnLan wol) _const_;
98 WakeOnLan wol_from_string(const char *wol) _pure_;
99
100 const char *port_to_string(NetDevPort port) _const_;
101 NetDevPort port_from_string(const char *port) _pure_;
102
103 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);
104 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);
105 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);
106 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);