Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2017, Mellanox Technologies. All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
0031  */
0032 
0033 #ifndef __MLX5E_REP_H__
0034 #define __MLX5E_REP_H__
0035 
0036 #include <net/ip_tunnels.h>
0037 #include <linux/rhashtable.h>
0038 #include <linux/mutex.h>
0039 #include "eswitch.h"
0040 #include "en.h"
0041 #include "lib/port_tun.h"
0042 
0043 #ifdef CONFIG_MLX5_ESWITCH
0044 extern const struct mlx5e_rx_handlers mlx5e_rx_handlers_rep;
0045 
0046 struct mlx5e_neigh_update_table {
0047     struct rhashtable       neigh_ht;
0048     /* Save the neigh hash entries in a list in addition to the hash table
0049      * (neigh_ht). In order to iterate easily over the neigh entries.
0050      * Used for stats query.
0051      */
0052     struct list_head    neigh_list;
0053     /* protect lookup/remove operations */
0054     struct mutex        encap_lock;
0055     struct notifier_block   netevent_nb;
0056     struct delayed_work     neigh_stats_work;
0057     unsigned long           min_interval; /* jiffies */
0058 };
0059 
0060 struct mlx5_tc_ct_priv;
0061 struct mlx5_tc_int_port_priv;
0062 struct mlx5e_rep_bond;
0063 struct mlx5e_tc_tun_encap;
0064 struct mlx5e_post_act;
0065 struct mlx5e_flow_meters;
0066 
0067 struct mlx5_rep_uplink_priv {
0068     /* indirect block callbacks are invoked on bind/unbind events
0069      * on registered higher level devices (e.g. tunnel devices)
0070      *
0071      * tc_indr_block_cb_priv_list is used to lookup indirect callback
0072      * private data
0073      *
0074      */
0075     struct list_head        tc_indr_block_priv_list;
0076 
0077     struct mlx5_tun_entropy tun_entropy;
0078 
0079     /* protects unready_flows */
0080     struct mutex                unready_flows_lock;
0081     struct list_head            unready_flows;
0082     struct work_struct          reoffload_flows_work;
0083 
0084     /* maps tun_info to a unique id*/
0085     struct mapping_ctx *tunnel_mapping;
0086     /* maps tun_enc_opts to a unique id*/
0087     struct mapping_ctx *tunnel_enc_opts_mapping;
0088 
0089     struct mlx5e_post_act *post_act;
0090     struct mlx5_tc_ct_priv *ct_priv;
0091     struct mlx5e_tc_psample *tc_psample;
0092 
0093     /* support eswitch vports bonding */
0094     struct mlx5e_rep_bond *bond;
0095 
0096     /* tc tunneling encapsulation private data */
0097     struct mlx5e_tc_tun_encap *encap;
0098 
0099     /* OVS internal port support */
0100     struct mlx5e_tc_int_port_priv *int_port_priv;
0101 
0102     struct mlx5e_flow_meters *flow_meters;
0103 };
0104 
0105 struct mlx5e_rep_priv {
0106     struct mlx5_eswitch_rep *rep;
0107     struct mlx5e_neigh_update_table neigh_update;
0108     struct net_device      *netdev;
0109     struct mlx5_flow_table *root_ft;
0110     struct mlx5_flow_handle *vport_rx_rule;
0111     struct list_head       vport_sqs_list;
0112     struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
0113     struct rtnl_link_stats64 prev_vf_vport_stats;
0114     struct rhashtable tc_ht;
0115 };
0116 
0117 static inline
0118 struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep)
0119 {
0120     return rep->rep_data[REP_ETH].priv;
0121 }
0122 
0123 struct mlx5e_neigh {
0124     union {
0125         __be32  v4;
0126         struct in6_addr v6;
0127     } dst_ip;
0128     int family;
0129 };
0130 
0131 struct mlx5e_neigh_hash_entry {
0132     struct rhash_head rhash_node;
0133     struct mlx5e_neigh m_neigh;
0134     struct mlx5e_priv *priv;
0135     struct net_device *neigh_dev;
0136 
0137     /* Save the neigh hash entry in a list on the representor in
0138      * addition to the hash table. In order to iterate easily over the
0139      * neighbour entries. Used for stats query.
0140      */
0141     struct list_head neigh_list;
0142 
0143     /* protects encap list */
0144     spinlock_t encap_list_lock;
0145     /* encap list sharing the same neigh */
0146     struct list_head encap_list;
0147 
0148     /* neigh hash entry can be deleted only when the refcount is zero.
0149      * refcount is needed to avoid neigh hash entry removal by TC, while
0150      * it's used by the neigh notification call.
0151      */
0152     refcount_t refcnt;
0153 
0154     /* Save the last reported time offloaded traffic pass over one of the
0155      * neigh hash entry flows. Use it to periodically update the neigh
0156      * 'used' value and avoid neigh deleting by the kernel.
0157      */
0158     unsigned long reported_lastuse;
0159 
0160     struct rcu_head rcu;
0161 };
0162 
0163 enum {
0164     /* set when the encap entry is successfully offloaded into HW */
0165     MLX5_ENCAP_ENTRY_VALID     = BIT(0),
0166     MLX5_REFORMAT_DECAP        = BIT(1),
0167     MLX5_ENCAP_ENTRY_NO_ROUTE  = BIT(2),
0168 };
0169 
0170 struct mlx5e_decap_key {
0171     struct ethhdr key;
0172 };
0173 
0174 struct mlx5e_decap_entry {
0175     struct mlx5e_decap_key key;
0176     struct list_head flows;
0177     struct hlist_node hlist;
0178     refcount_t refcnt;
0179     struct completion res_ready;
0180     int compl_result;
0181     struct mlx5_pkt_reformat *pkt_reformat;
0182     struct rcu_head rcu;
0183 };
0184 
0185 struct mlx5e_mpls_info {
0186     u32             label;
0187     u8              tc;
0188     u8              bos;
0189     u8              ttl;
0190 };
0191 
0192 struct mlx5e_encap_entry {
0193     /* attached neigh hash entry */
0194     struct mlx5e_neigh_hash_entry *nhe;
0195     /* neigh hash entry list of encaps sharing the same neigh */
0196     struct list_head encap_list;
0197     /* a node of the eswitch encap hash table which keeping all the encap
0198      * entries
0199      */
0200     struct hlist_node encap_hlist;
0201     struct list_head flows;
0202     struct list_head route_list;
0203     struct mlx5_pkt_reformat *pkt_reformat;
0204     const struct ip_tunnel_info *tun_info;
0205     struct mlx5e_mpls_info mpls_info;
0206     unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
0207 
0208     struct net_device *out_dev;
0209     int route_dev_ifindex;
0210     struct mlx5e_tc_tunnel *tunnel;
0211     int reformat_type;
0212     u8 flags;
0213     char *encap_header;
0214     int encap_size;
0215     refcount_t refcnt;
0216     struct completion res_ready;
0217     int compl_result;
0218     struct rcu_head rcu;
0219 };
0220 
0221 struct mlx5e_rep_sq {
0222     struct mlx5_flow_handle *send_to_vport_rule;
0223     struct mlx5_flow_handle *send_to_vport_rule_peer;
0224     u32 sqn;
0225     struct list_head     list;
0226 };
0227 
0228 int mlx5e_rep_init(void);
0229 void mlx5e_rep_cleanup(void);
0230 int mlx5e_rep_bond_init(struct mlx5e_rep_priv *rpriv);
0231 void mlx5e_rep_bond_cleanup(struct mlx5e_rep_priv *rpriv);
0232 int mlx5e_rep_bond_enslave(struct mlx5_eswitch *esw, struct net_device *netdev,
0233                struct net_device *lag_dev);
0234 void mlx5e_rep_bond_unslave(struct mlx5_eswitch *esw,
0235                 const struct net_device *netdev,
0236                 const struct net_device *lag_dev);
0237 int mlx5e_rep_bond_update(struct mlx5e_priv *priv, bool cleanup);
0238 
0239 bool mlx5e_rep_has_offload_stats(const struct net_device *dev, int attr_id);
0240 int mlx5e_rep_get_offload_stats(int attr_id, const struct net_device *dev,
0241                 void *sp);
0242 
0243 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv);
0244 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
0245 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
0246 
0247 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv);
0248 
0249 bool mlx5e_eswitch_vf_rep(const struct net_device *netdev);
0250 bool mlx5e_eswitch_uplink_rep(const struct net_device *netdev);
0251 static inline bool mlx5e_eswitch_rep(const struct net_device *netdev)
0252 {
0253     return mlx5e_eswitch_vf_rep(netdev) ||
0254            mlx5e_eswitch_uplink_rep(netdev);
0255 }
0256 
0257 #else /* CONFIG_MLX5_ESWITCH */
0258 static inline bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv) { return false; }
0259 static inline int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv) { return 0; }
0260 static inline void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv) {}
0261 static inline int mlx5e_rep_init(void) { return 0; };
0262 static inline void mlx5e_rep_cleanup(void) {};
0263 static inline bool mlx5e_rep_has_offload_stats(const struct net_device *dev,
0264                            int attr_id) { return false; }
0265 static inline int mlx5e_rep_get_offload_stats(int attr_id,
0266                           const struct net_device *dev,
0267                           void *sp) { return -EOPNOTSUPP; }
0268 #endif
0269 
0270 static inline bool mlx5e_is_vport_rep(struct mlx5e_priv *priv)
0271 {
0272     return (MLX5_ESWITCH_MANAGER(priv->mdev) && priv->ppriv);
0273 }
0274 #endif /* __MLX5E_REP_H__ */