linux/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
   2/* Copyright (c) 2018 Mellanox Technologies. */
   3
   4#ifndef __MLX5E_FLOW_STEER_H__
   5#define __MLX5E_FLOW_STEER_H__
   6
   7enum {
   8        MLX5E_TC_FT_LEVEL = 0,
   9        MLX5E_TC_TTC_FT_LEVEL,
  10};
  11
  12struct mlx5e_tc_table {
  13        struct mlx5_flow_table          *t;
  14
  15        struct rhashtable               ht;
  16
  17        DECLARE_HASHTABLE(mod_hdr_tbl, 8);
  18        DECLARE_HASHTABLE(hairpin_tbl, 8);
  19
  20        struct notifier_block     netdevice_nb;
  21};
  22
  23struct mlx5e_flow_table {
  24        int num_groups;
  25        struct mlx5_flow_table *t;
  26        struct mlx5_flow_group **g;
  27};
  28
  29struct mlx5e_l2_rule {
  30        u8  addr[ETH_ALEN + 2];
  31        struct mlx5_flow_handle *rule;
  32};
  33
  34#define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
  35
  36struct mlx5e_vlan_table {
  37        struct mlx5e_flow_table         ft;
  38        DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
  39        DECLARE_BITMAP(active_svlans, VLAN_N_VID);
  40        struct mlx5_flow_handle *active_cvlans_rule[VLAN_N_VID];
  41        struct mlx5_flow_handle *active_svlans_rule[VLAN_N_VID];
  42        struct mlx5_flow_handle *untagged_rule;
  43        struct mlx5_flow_handle *any_cvlan_rule;
  44        struct mlx5_flow_handle *any_svlan_rule;
  45        bool                    cvlan_filter_disabled;
  46};
  47
  48struct mlx5e_l2_table {
  49        struct mlx5e_flow_table    ft;
  50        struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
  51        struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
  52        struct mlx5e_l2_rule       broadcast;
  53        struct mlx5e_l2_rule       allmulti;
  54        struct mlx5e_l2_rule       promisc;
  55        bool                       broadcast_enabled;
  56        bool                       allmulti_enabled;
  57        bool                       promisc_enabled;
  58};
  59
  60enum mlx5e_traffic_types {
  61        MLX5E_TT_IPV4_TCP,
  62        MLX5E_TT_IPV6_TCP,
  63        MLX5E_TT_IPV4_UDP,
  64        MLX5E_TT_IPV6_UDP,
  65        MLX5E_TT_IPV4_IPSEC_AH,
  66        MLX5E_TT_IPV6_IPSEC_AH,
  67        MLX5E_TT_IPV4_IPSEC_ESP,
  68        MLX5E_TT_IPV6_IPSEC_ESP,
  69        MLX5E_TT_IPV4,
  70        MLX5E_TT_IPV6,
  71        MLX5E_TT_ANY,
  72        MLX5E_NUM_TT,
  73        MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
  74};
  75
  76struct mlx5e_tirc_config {
  77        u8 l3_prot_type;
  78        u8 l4_prot_type;
  79        u32 rx_hash_fields;
  80};
  81
  82#define MLX5_HASH_IP            (MLX5_HASH_FIELD_SEL_SRC_IP   |\
  83                                 MLX5_HASH_FIELD_SEL_DST_IP)
  84#define MLX5_HASH_IP_L4PORTS    (MLX5_HASH_FIELD_SEL_SRC_IP   |\
  85                                 MLX5_HASH_FIELD_SEL_DST_IP   |\
  86                                 MLX5_HASH_FIELD_SEL_L4_SPORT |\
  87                                 MLX5_HASH_FIELD_SEL_L4_DPORT)
  88#define MLX5_HASH_IP_IPSEC_SPI  (MLX5_HASH_FIELD_SEL_SRC_IP   |\
  89                                 MLX5_HASH_FIELD_SEL_DST_IP   |\
  90                                 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
  91
  92enum mlx5e_tunnel_types {
  93        MLX5E_TT_IPV4_GRE,
  94        MLX5E_TT_IPV6_GRE,
  95        MLX5E_NUM_TUNNEL_TT,
  96};
  97
  98/* L3/L4 traffic type classifier */
  99struct mlx5e_ttc_table {
 100        struct mlx5e_flow_table  ft;
 101        struct mlx5_flow_handle  *rules[MLX5E_NUM_TT];
 102        struct mlx5_flow_handle  *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
 103};
 104
 105/* NIC prio FTS */
 106enum {
 107        MLX5E_VLAN_FT_LEVEL = 0,
 108        MLX5E_L2_FT_LEVEL,
 109        MLX5E_TTC_FT_LEVEL,
 110        MLX5E_INNER_TTC_FT_LEVEL,
 111#ifdef CONFIG_MLX5_EN_ARFS
 112        MLX5E_ARFS_FT_LEVEL
 113#endif
 114};
 115
 116#ifdef CONFIG_MLX5_EN_RXNFC
 117
 118struct mlx5e_ethtool_table {
 119        struct mlx5_flow_table *ft;
 120        int                    num_rules;
 121};
 122
 123#define ETHTOOL_NUM_L3_L4_FTS 7
 124#define ETHTOOL_NUM_L2_FTS 4
 125
 126struct mlx5e_ethtool_steering {
 127        struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
 128        struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
 129        struct list_head                rules;
 130        int                             tot_num_rules;
 131};
 132
 133void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
 134void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
 135int mlx5e_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
 136int mlx5e_get_rxnfc(struct net_device *dev,
 137                    struct ethtool_rxnfc *info, u32 *rule_locs);
 138#else
 139static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv)    { }
 140static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
 141#endif /* CONFIG_MLX5_EN_RXNFC */
 142
 143#ifdef CONFIG_MLX5_EN_ARFS
 144#define ARFS_HASH_SHIFT BITS_PER_BYTE
 145#define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
 146
 147struct arfs_table {
 148        struct mlx5e_flow_table  ft;
 149        struct mlx5_flow_handle  *default_rule;
 150        struct hlist_head        rules_hash[ARFS_HASH_SIZE];
 151};
 152
 153enum  arfs_type {
 154        ARFS_IPV4_TCP,
 155        ARFS_IPV6_TCP,
 156        ARFS_IPV4_UDP,
 157        ARFS_IPV6_UDP,
 158        ARFS_NUM_TYPES,
 159};
 160
 161struct mlx5e_arfs_tables {
 162        struct arfs_table arfs_tables[ARFS_NUM_TYPES];
 163        /* Protect aRFS rules list */
 164        spinlock_t                     arfs_lock;
 165        struct list_head               rules;
 166        int                            last_filter_id;
 167        struct workqueue_struct        *wq;
 168};
 169
 170int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
 171void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
 172int mlx5e_arfs_enable(struct mlx5e_priv *priv);
 173int mlx5e_arfs_disable(struct mlx5e_priv *priv);
 174int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
 175                        u16 rxq_index, u32 flow_id);
 176#else
 177static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
 178static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
 179static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
 180static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
 181#endif
 182
 183struct mlx5e_flow_steering {
 184        struct mlx5_flow_namespace      *ns;
 185#ifdef CONFIG_MLX5_EN_RXNFC
 186        struct mlx5e_ethtool_steering   ethtool;
 187#endif
 188        struct mlx5e_tc_table           tc;
 189        struct mlx5e_vlan_table         vlan;
 190        struct mlx5e_l2_table           l2;
 191        struct mlx5e_ttc_table          ttc;
 192        struct mlx5e_ttc_table          inner_ttc;
 193#ifdef CONFIG_MLX5_EN_ARFS
 194        struct mlx5e_arfs_tables        arfs;
 195#endif
 196};
 197
 198struct ttc_params {
 199        struct mlx5_flow_table_attr ft_attr;
 200        u32 any_tt_tirn;
 201        u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
 202        struct mlx5e_ttc_table *inner_ttc;
 203};
 204
 205void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
 206void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
 207void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
 208
 209int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
 210                           struct mlx5e_ttc_table *ttc);
 211void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
 212                             struct mlx5e_ttc_table *ttc);
 213
 214int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
 215                                 struct mlx5e_ttc_table *ttc);
 216void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
 217                                   struct mlx5e_ttc_table *ttc);
 218
 219void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
 220
 221void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
 222void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
 223
 224int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
 225void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
 226
 227#endif /* __MLX5E_FLOW_STEER_H__ */
 228
 229