2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2016-02-16 20:05:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
2013-10-28 20:59:56 +01:00
|
|
|
#include <macro.h>
|
2019-01-07 12:16:18 +01:00
|
|
|
#include <net/ethernet.h>
|
2016-11-04 10:55:07 +01:00
|
|
|
#include <linux/ethtool.h>
|
|
|
|
|
2018-11-12 08:45:04 +01:00
|
|
|
#include "conf-parser.h"
|
2013-10-28 20:59:56 +01:00
|
|
|
|
2019-06-25 04:55:04 +02:00
|
|
|
#define N_ADVERTISE 3
|
2017-06-26 00:42:57 +02:00
|
|
|
|
2013-10-28 20:59:56 +01:00
|
|
|
/* we can't use DUPLEX_ prefix, as it
|
|
|
|
* clashes with <linux/ethtool.h> */
|
|
|
|
typedef enum Duplex {
|
2017-06-30 18:55:21 +02:00
|
|
|
DUP_HALF = DUPLEX_HALF,
|
|
|
|
DUP_FULL = DUPLEX_FULL,
|
2013-10-28 20:59:56 +01:00
|
|
|
_DUP_MAX,
|
|
|
|
_DUP_INVALID = -1
|
|
|
|
} Duplex;
|
|
|
|
|
|
|
|
typedef enum WakeOnLan {
|
|
|
|
WOL_PHY,
|
2017-08-31 12:44:43 +02:00
|
|
|
WOL_UCAST,
|
|
|
|
WOL_MCAST,
|
|
|
|
WOL_BCAST,
|
|
|
|
WOL_ARP,
|
2013-10-28 20:59:56 +01:00
|
|
|
WOL_MAGIC,
|
2017-08-31 12:44:43 +02:00
|
|
|
WOL_MAGICSECURE,
|
2013-10-28 20:59:56 +01:00
|
|
|
WOL_OFF,
|
|
|
|
_WOL_MAX,
|
|
|
|
_WOL_INVALID = -1
|
|
|
|
} WakeOnLan;
|
|
|
|
|
2016-08-30 16:52:04 +02:00
|
|
|
typedef enum NetDevFeature {
|
2020-01-27 11:49:25 +01:00
|
|
|
NET_DEV_FEAT_RX,
|
|
|
|
NET_DEV_FEAT_TX,
|
2016-08-30 16:52:04 +02:00
|
|
|
NET_DEV_FEAT_GSO,
|
2016-08-31 09:17:02 +02:00
|
|
|
NET_DEV_FEAT_GRO,
|
|
|
|
NET_DEV_FEAT_LRO,
|
2016-08-30 16:52:04 +02:00
|
|
|
NET_DEV_FEAT_TSO,
|
2017-09-19 10:49:58 +02:00
|
|
|
NET_DEV_FEAT_TSO6,
|
2016-08-30 16:52:04 +02:00
|
|
|
_NET_DEV_FEAT_MAX,
|
|
|
|
_NET_DEV_FEAT_INVALID = -1
|
|
|
|
} NetDevFeature;
|
|
|
|
|
2017-06-26 00:42:57 +02:00
|
|
|
typedef enum NetDevPort {
|
2019-01-07 19:28:47 +01:00
|
|
|
NET_DEV_PORT_TP = PORT_TP,
|
|
|
|
NET_DEV_PORT_AUI = PORT_AUI,
|
|
|
|
NET_DEV_PORT_MII = PORT_MII,
|
|
|
|
NET_DEV_PORT_FIBRE = PORT_FIBRE,
|
|
|
|
NET_DEV_PORT_BNC = PORT_BNC,
|
|
|
|
NET_DEV_PORT_DA = PORT_DA,
|
|
|
|
NET_DEV_PORT_NONE = PORT_NONE,
|
|
|
|
NET_DEV_PORT_OTHER = PORT_OTHER,
|
2017-06-26 00:42:57 +02:00
|
|
|
_NET_DEV_PORT_MAX,
|
|
|
|
_NET_DEV_PORT_INVALID = -1
|
|
|
|
} NetDevPort;
|
2016-11-04 10:55:07 +01:00
|
|
|
|
|
|
|
#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
|
2017-09-16 20:36:56 +02:00
|
|
|
#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBYTES (4 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32)
|
2016-11-04 10:55:07 +01:00
|
|
|
|
|
|
|
/* layout of the struct passed from/to userland */
|
|
|
|
struct ethtool_link_usettings {
|
|
|
|
struct ethtool_link_settings base;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32_t supported[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
|
|
|
|
uint32_t advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
|
|
|
|
uint32_t lp_advertising[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
|
|
|
|
} link_modes;
|
|
|
|
};
|
|
|
|
|
2018-05-08 13:03:41 +02:00
|
|
|
typedef struct netdev_channels {
|
|
|
|
uint32_t rx_count;
|
|
|
|
uint32_t tx_count;
|
|
|
|
uint32_t other_count;
|
|
|
|
uint32_t combined_count;
|
|
|
|
|
|
|
|
bool rx_count_set;
|
|
|
|
bool tx_count_set;
|
|
|
|
bool other_count_set;
|
|
|
|
bool combined_count_set;
|
|
|
|
} netdev_channels;
|
|
|
|
|
2019-09-23 16:51:02 +02:00
|
|
|
typedef struct netdev_ring_param {
|
|
|
|
uint32_t rx_pending;
|
2020-04-29 02:00:25 +02:00
|
|
|
uint32_t rx_mini_pending;
|
|
|
|
uint32_t rx_jumbo_pending;
|
2019-09-23 16:51:02 +02:00
|
|
|
uint32_t tx_pending;
|
|
|
|
|
|
|
|
bool rx_pending_set;
|
2020-04-29 02:00:25 +02:00
|
|
|
bool rx_mini_pending_set;
|
|
|
|
bool rx_jumbo_pending_set;
|
2019-09-23 16:51:02 +02:00
|
|
|
bool tx_pending_set;
|
|
|
|
} netdev_ring_param;
|
|
|
|
|
2020-01-08 11:55:07 +01:00
|
|
|
int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
|
|
|
|
int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
|
2020-01-21 12:06:40 +01:00
|
|
|
int *ret_autonegotiation, uint64_t *ret_speed,
|
2019-06-17 08:31:20 +02:00
|
|
|
Duplex *ret_duplex, NetDevPort *ret_port);
|
2020-01-08 11:55:07 +01:00
|
|
|
int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
|
|
|
|
int ethtool_set_speed(int *ethtool_fd, const char *ifname, unsigned speed, Duplex duplex);
|
|
|
|
int ethtool_set_wol(int *ethtool_fd, const char *ifname, WakeOnLan wol);
|
2020-09-15 03:40:54 +02:00
|
|
|
int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring);
|
|
|
|
int ethtool_set_features(int *ethtool_fd, const char *ifname, const int *features);
|
2020-01-08 11:55:07 +01:00
|
|
|
int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
|
2020-09-15 03:40:54 +02:00
|
|
|
int autonegotiation, const uint32_t advertise[static N_ADVERTISE],
|
2020-01-21 12:06:40 +01:00
|
|
|
uint64_t speed, Duplex duplex, NetDevPort port);
|
2020-09-15 03:40:54 +02:00
|
|
|
int ethtool_set_channels(int *ethtool_fd, const char *ifname, const netdev_channels *channels);
|
2020-02-07 12:06:44 +01:00
|
|
|
int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int autoneg);
|
2013-10-28 20:59:56 +01:00
|
|
|
|
|
|
|
const char *duplex_to_string(Duplex d) _const_;
|
|
|
|
Duplex duplex_from_string(const char *d) _pure_;
|
|
|
|
|
|
|
|
const char *wol_to_string(WakeOnLan wol) _const_;
|
|
|
|
WakeOnLan wol_from_string(const char *wol) _pure_;
|
|
|
|
|
2017-06-26 00:42:57 +02:00
|
|
|
const char *port_to_string(NetDevPort port) _const_;
|
|
|
|
NetDevPort port_from_string(const char *port) _pure_;
|
|
|
|
|
2018-11-17 15:08:22 +01:00
|
|
|
const char *ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val) _const_;
|
|
|
|
enum ethtool_link_mode_bit_indices ethtool_link_mode_bit_from_string(const char *str) _pure_;
|
2017-09-16 20:36:56 +02:00
|
|
|
|
2018-11-12 08:45:04 +01:00
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_duplex);
|
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_wol);
|
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_port);
|
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_channel);
|
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_advertise);
|
2019-09-23 16:51:02 +02:00
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_nic_buffer_size);
|