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