]>
Commit | Line | Data |
---|---|---|
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> */ | |
14 | typedef 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 | 21 | typedef 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 | 33 | typedef 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 */ | |
50 | struct 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 | ||
5f945202 SS |
60 | typedef struct netdev_channels { |
61 | uint32_t rx_count; | |
62 | uint32_t tx_count; | |
63 | uint32_t other_count; | |
64 | uint32_t combined_count; | |
65 | ||
66 | bool rx_count_set; | |
67 | bool tx_count_set; | |
68 | bool other_count_set; | |
69 | bool combined_count_set; | |
70 | } netdev_channels; | |
71 | ||
224ded67 | 72 | typedef struct netdev_ring_param { |
406041b7 DDM |
73 | /* For any of the 4 following settings, a value of 0 indicates the hardware advertised maximum should |
74 | * be used. */ | |
224ded67 | 75 | uint32_t rx_pending; |
e81f5fc4 | 76 | uint32_t rx_mini_pending; |
77 | uint32_t rx_jumbo_pending; | |
224ded67 SS |
78 | uint32_t tx_pending; |
79 | ||
80 | bool rx_pending_set; | |
e81f5fc4 | 81 | bool rx_mini_pending_set; |
82 | bool rx_jumbo_pending_set; | |
224ded67 SS |
83 | bool tx_pending_set; |
84 | } netdev_ring_param; | |
85 | ||
64be35ab ZJS |
86 | int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret); |
87 | int ethtool_get_link_info(int *ethtool_fd, const char *ifname, | |
50299121 | 88 | int *ret_autonegotiation, uint64_t *ret_speed, |
33a8695f | 89 | Duplex *ret_duplex, NetDevPort *ret_port); |
64be35ab | 90 | int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret); |
c50404ae | 91 | int ethtool_set_wol(int *ethtool_fd, const char *ifname, uint32_t wolopts); |
cadc7ed2 | 92 | int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring); |
0db68800 | 93 | int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]); |
64be35ab | 94 | int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname, |
cadc7ed2 | 95 | int autonegotiation, const uint32_t advertise[static N_ADVERTISE], |
50299121 | 96 | uint64_t speed, Duplex duplex, NetDevPort port); |
cadc7ed2 | 97 | int ethtool_set_channels(int *ethtool_fd, const char *ifname, const netdev_channels *channels); |
a34811e4 | 98 | int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg); |
5fde13d7 TG |
99 | |
100 | const char *duplex_to_string(Duplex d) _const_; | |
101 | Duplex duplex_from_string(const char *d) _pure_; | |
102 | ||
c50404ae | 103 | int wol_options_to_string_alloc(uint32_t opts, char **ret); |
5fde13d7 | 104 | |
593022fa SS |
105 | const char *port_to_string(NetDevPort port) _const_; |
106 | NetDevPort port_from_string(const char *port) _pure_; | |
107 | ||
2d18ac44 YW |
108 | const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val) _const_; |
109 | enum ethtool_link_mode_bit_indices ethtool_link_mode_bit_from_string(const char *str) _pure_; | |
6cf0a204 | 110 | |
538f15cf YW |
111 | CONFIG_PARSER_PROTOTYPE(config_parse_duplex); |
112 | CONFIG_PARSER_PROTOTYPE(config_parse_wol); | |
113 | CONFIG_PARSER_PROTOTYPE(config_parse_port); | |
114 | CONFIG_PARSER_PROTOTYPE(config_parse_channel); | |
115 | CONFIG_PARSER_PROTOTYPE(config_parse_advertise); | |
224ded67 | 116 | CONFIG_PARSER_PROTOTYPE(config_parse_nic_buffer_size); |