cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

lag.h (3146B)


      1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
      2/* Copyright (c) 2019 Mellanox Technologies. */
      3
      4#ifndef __MLX5_LAG_H__
      5#define __MLX5_LAG_H__
      6
      7#include <linux/debugfs.h>
      8
      9#define MLX5_LAG_MAX_HASH_BUCKETS 16
     10#include "mlx5_core.h"
     11#include "mp.h"
     12#include "port_sel.h"
     13#include "mpesw.h"
     14
     15enum {
     16	MLX5_LAG_P1,
     17	MLX5_LAG_P2,
     18};
     19
     20enum {
     21	MLX5_LAG_FLAG_NDEVS_READY,
     22};
     23
     24enum {
     25	MLX5_LAG_MODE_FLAG_HASH_BASED,
     26	MLX5_LAG_MODE_FLAG_SHARED_FDB,
     27};
     28
     29enum mlx5_lag_mode {
     30	MLX5_LAG_MODE_NONE,
     31	MLX5_LAG_MODE_ROCE,
     32	MLX5_LAG_MODE_SRIOV,
     33	MLX5_LAG_MODE_MULTIPATH,
     34	MLX5_LAG_MODE_MPESW,
     35};
     36
     37struct lag_func {
     38	struct mlx5_core_dev *dev;
     39	struct net_device    *netdev;
     40	bool has_drop;
     41};
     42
     43/* Used for collection of netdev event info. */
     44struct lag_tracker {
     45	enum   netdev_lag_tx_type           tx_type;
     46	struct netdev_lag_lower_state_info  netdev_state[MLX5_MAX_PORTS];
     47	unsigned int is_bonded:1;
     48	unsigned int has_inactive:1;
     49	enum netdev_lag_hash hash_type;
     50};
     51
     52/* LAG data of a ConnectX card.
     53 * It serves both its phys functions.
     54 */
     55struct mlx5_lag {
     56	enum mlx5_lag_mode        mode;
     57	unsigned long		  mode_flags;
     58	unsigned long		  state_flags;
     59	u8			  ports;
     60	u8			  buckets;
     61	int			  mode_changes_in_progress;
     62	u8			  v2p_map[MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS];
     63	struct kref               ref;
     64	struct lag_func           pf[MLX5_MAX_PORTS];
     65	struct lag_tracker        tracker;
     66	struct workqueue_struct   *wq;
     67	struct delayed_work       bond_work;
     68	struct work_struct	  mpesw_work;
     69	struct notifier_block     nb;
     70	struct lag_mp             lag_mp;
     71	struct mlx5_lag_port_sel  port_sel;
     72	/* Protect lag fields/state changes */
     73	struct mutex		  lock;
     74	struct lag_mpesw	  lag_mpesw;
     75};
     76
     77static inline bool mlx5_is_lag_supported(struct mlx5_core_dev *dev)
     78{
     79	if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
     80	    !MLX5_CAP_GEN(dev, lag_master) ||
     81	    MLX5_CAP_GEN(dev, num_lag_ports) < 2 ||
     82	    MLX5_CAP_GEN(dev, num_lag_ports) > MLX5_MAX_PORTS)
     83		return false;
     84	return true;
     85}
     86
     87static inline struct mlx5_lag *
     88mlx5_lag_dev(struct mlx5_core_dev *dev)
     89{
     90	return dev->priv.lag;
     91}
     92
     93static inline bool
     94__mlx5_lag_is_active(struct mlx5_lag *ldev)
     95{
     96	return ldev->mode != MLX5_LAG_MODE_NONE;
     97}
     98
     99static inline bool
    100mlx5_lag_is_ready(struct mlx5_lag *ldev)
    101{
    102	return test_bit(MLX5_LAG_FLAG_NDEVS_READY, &ldev->state_flags);
    103}
    104
    105void mlx5_modify_lag(struct mlx5_lag *ldev,
    106		     struct lag_tracker *tracker);
    107int mlx5_activate_lag(struct mlx5_lag *ldev,
    108		      struct lag_tracker *tracker,
    109		      enum mlx5_lag_mode mode,
    110		      bool shared_fdb);
    111int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
    112				struct net_device *ndev);
    113bool mlx5_shared_fdb_supported(struct mlx5_lag *ldev);
    114void mlx5_lag_del_mpesw_rule(struct mlx5_core_dev *dev);
    115int mlx5_lag_add_mpesw_rule(struct mlx5_core_dev *dev);
    116
    117char *mlx5_get_str_port_sel_mode(struct mlx5_lag *ldev);
    118void mlx5_infer_tx_enabled(struct lag_tracker *tracker, u8 num_ports,
    119			   u8 *ports, int *num_enabled);
    120
    121void mlx5_ldev_add_debugfs(struct mlx5_core_dev *dev);
    122void mlx5_ldev_remove_debugfs(struct dentry *dbg);
    123void mlx5_disable_lag(struct mlx5_lag *ldev);
    124
    125#endif /* __MLX5_LAG_H__ */