Skip to content

Commit

Permalink
libbpf: add functions to get XSK modes
Browse files Browse the repository at this point in the history
Add functions to get XDP/XSK modes from netdev feature flags
over netlink ethtool family interface. These functions provide
functionalities that are going to be used in upcoming changes
together constituting new libbpf public API function which
informs about key xsk capabilities of given network interface.

Signed-off-by: Marek Majtyka <marekx.majtyka@intel.com>
  • Loading branch information
alardam authored and intel-lab-lkp committed Nov 16, 2020
1 parent 1962c0a commit fd9c137
Show file tree
Hide file tree
Showing 4 changed files with 469 additions and 4 deletions.
44 changes: 44 additions & 0 deletions tools/include/uapi/linux/ethtool.h
Expand Up @@ -48,4 +48,48 @@ struct ethtool_channels {
__u32 combined_count;
};

#define ETH_GSTRING_LEN 32

/**
* enum ethtool_stringset - string set ID
* @ETH_SS_TEST: Self-test result names, for use with %ETHTOOL_TEST
* @ETH_SS_STATS: Statistic names, for use with %ETHTOOL_GSTATS
* @ETH_SS_PRIV_FLAGS: Driver private flag names, for use with
* %ETHTOOL_GPFLAGS and %ETHTOOL_SPFLAGS
* @ETH_SS_NTUPLE_FILTERS: Previously used with %ETHTOOL_GRXNTUPLE;
* now deprecated
* @ETH_SS_FEATURES: Device feature names
* @ETH_SS_RSS_HASH_FUNCS: RSS hush function names
* @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS
* @ETH_SS_PHY_TUNABLES: PHY tunable names
* @ETH_SS_LINK_MODES: link mode names
* @ETH_SS_MSG_CLASSES: debug message class names
* @ETH_SS_WOL_MODES: wake-on-lan modes
* @ETH_SS_SOF_TIMESTAMPING: SOF_TIMESTAMPING_* flags
* @ETH_SS_TS_TX_TYPES: timestamping Tx types
* @ETH_SS_TS_RX_FILTERS: timestamping Rx filters
* @ETH_SS_UDP_TUNNEL_TYPES: UDP tunnel types
*/
enum ethtool_stringset {
ETH_SS_TEST = 0,
ETH_SS_STATS,
ETH_SS_PRIV_FLAGS,
ETH_SS_NTUPLE_FILTERS,
ETH_SS_FEATURES,
ETH_SS_RSS_HASH_FUNCS,
ETH_SS_TUNABLES,
ETH_SS_PHY_STATS,
ETH_SS_PHY_TUNABLES,
ETH_SS_LINK_MODES,
ETH_SS_MSG_CLASSES,
ETH_SS_WOL_MODES,
ETH_SS_SOF_TIMESTAMPING,
ETH_SS_TS_TX_TYPES,
ETH_SS_TS_RX_FILTERS,
ETH_SS_UDP_TUNNEL_TYPES,

/* add new constants above here */
ETH_SS_COUNT
};

#endif /* _UAPI_LINUX_ETHTOOL_H */
49 changes: 49 additions & 0 deletions tools/lib/bpf/ethtool.h
@@ -0,0 +1,49 @@
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */

/*
* Generic netlink ethtool family required defines
*
* Copyright (c) 2020 Intel
*/

#ifndef __LIBBPF_ETHTOOL_H_
#define __LIBBPF_ETHTOOL_H_

#include <linux/ethtool_netlink.h>

#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define FEATURE_BITS_TO_BLOCKS(n_bits) DIV_ROUND_UP(n_bits, 32U)

#define FEATURE_WORD(blocks, index) ((blocks)[(index) / 32U])
#define FEATURE_FIELD_FLAG(index) (1U << (index) % 32U)
#define FEATURE_BIT_IS_SET(blocks, index) \
(FEATURE_WORD(blocks, index) & FEATURE_FIELD_FLAG(index))

#define NETDEV_XDP_STR "xdp"
#define NETDEV_XDP_LEN 4

#define NETDEV_AF_XDP_ZC_STR "af-xdp-zc"
#define NETDEV_AF_XDP_ZC_LEN 10

#define BUF_SIZE_4096 4096
#define BUF_SIZE_8192 8192

#define MAX_FEATURES 500

struct ethnl_params {
const char *ifname;
const char *nl_family;
int features;
int xdp_idx;
int xdp_zc_idx;
int xdp_flags;
int xdp_zc_flags;
__u16 fam_id;
};

int libbpf_ethnl_get_ethtool_family_id(struct ethnl_params *param);
int libbpf_ethnl_get_netdev_features(struct ethnl_params *param);
int libbpf_ethnl_get_active_bits(struct ethnl_params *param);

#endif /* __LIBBPF_ETHTOOL_H_ */

1 change: 1 addition & 0 deletions tools/lib/bpf/libbpf.h
Expand Up @@ -41,6 +41,7 @@ enum libbpf_errno {
LIBBPF_ERRNO__WRNGPID, /* Wrong pid in netlink message */
LIBBPF_ERRNO__INVSEQ, /* Invalid netlink sequence */
LIBBPF_ERRNO__NLPARSE, /* netlink parsing error */
LIBBPF_ERRNO__INVXDP, /* Invalid XDP data */
__LIBBPF_ERRNO__END,
};

Expand Down

0 comments on commit fd9c137

Please sign in to comment.