]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/net/ethtool-util.h
systemd-link: add support to configure the device port (#6153)
[thirdparty/systemd.git] / src / udev / net / ethtool-util.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <macro.h>
23 #include <linux/ethtool.h>
24
25 #include "missing.h"
26
27 struct link_config;
28
29 /* we can't use DUPLEX_ prefix, as it
30 * clashes with <linux/ethtool.h> */
31 typedef enum Duplex {
32 DUP_FULL,
33 DUP_HALF,
34 _DUP_MAX,
35 _DUP_INVALID = -1
36 } Duplex;
37
38 typedef enum WakeOnLan {
39 WOL_PHY,
40 WOL_MAGIC,
41 WOL_OFF,
42 _WOL_MAX,
43 _WOL_INVALID = -1
44 } WakeOnLan;
45
46 typedef enum NetDevFeature {
47 NET_DEV_FEAT_GSO,
48 NET_DEV_FEAT_GRO,
49 NET_DEV_FEAT_LRO,
50 NET_DEV_FEAT_TSO,
51 NET_DEV_FEAT_UFO,
52 _NET_DEV_FEAT_MAX,
53 _NET_DEV_FEAT_INVALID = -1
54 } NetDevFeature;
55
56 typedef enum NetDevPort {
57 NET_DEV_PORT_TP = 0x00,
58 NET_DEV_PORT_AUI = 0x01,
59 NET_DEV_PORT_MII = 0x02,
60 NET_DEV_PORT_FIBRE = 0x03,
61 NET_DEV_PORT_BNC = 0x04,
62 NET_DEV_PORT_DA = 0x05,
63 NET_DEV_PORT_NONE = 0xef,
64 NET_DEV_PORT_OTHER = 0xff,
65 _NET_DEV_PORT_MAX,
66 _NET_DEV_PORT_INVALID = -1
67 } NetDevPort;
68
69 #define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
70
71 /* layout of the struct passed from/to userland */
72 struct ethtool_link_usettings {
73 struct ethtool_link_settings base;
74
75 struct {
76 uint32_t supported[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
77 uint32_t advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
78 uint32_t lp_advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
79 } link_modes;
80 };
81
82 int ethtool_connect(int *ret);
83
84 int ethtool_get_driver(int *fd, const char *ifname, char **ret);
85 int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex);
86 int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
87 int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features);
88 int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *link);
89
90 const char *duplex_to_string(Duplex d) _const_;
91 Duplex duplex_from_string(const char *d) _pure_;
92
93 const char *wol_to_string(WakeOnLan wol) _const_;
94 WakeOnLan wol_from_string(const char *wol) _pure_;
95
96 const char *port_to_string(NetDevPort port) _const_;
97 NetDevPort port_from_string(const char *port) _pure_;
98
99 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);
100 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);
101 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);