Back to home page

OSCL-LXR

 
 

    


0001 /* Broadcom NetXtreme-C/E network driver.
0002  *
0003  * Copyright (c) 2017 Broadcom Limited
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation.
0008  */
0009 
0010 #ifndef BNXT_TC_H
0011 #define BNXT_TC_H
0012 
0013 #ifdef CONFIG_BNXT_FLOWER_OFFLOAD
0014 
0015 #include <net/ip_tunnels.h>
0016 
0017 /* Structs used for storing the filter/actions of the TC cmd.
0018  */
0019 struct bnxt_tc_l2_key {
0020     u8      dmac[ETH_ALEN];
0021     u8      smac[ETH_ALEN];
0022     __be16      inner_vlan_tpid;
0023     __be16      inner_vlan_tci;
0024     __be16      ether_type;
0025     u8      num_vlans;
0026     u8      dir;
0027 #define BNXT_DIR_RX 1
0028 #define BNXT_DIR_TX 0
0029 };
0030 
0031 struct bnxt_tc_l3_key {
0032     union {
0033         struct {
0034             struct in_addr daddr;
0035             struct in_addr saddr;
0036         } ipv4;
0037         struct {
0038             struct in6_addr daddr;
0039             struct in6_addr saddr;
0040         } ipv6;
0041     };
0042 };
0043 
0044 struct bnxt_tc_l4_key {
0045     u8  ip_proto;
0046     union {
0047         struct {
0048             __be16 sport;
0049             __be16 dport;
0050         } ports;
0051         struct {
0052             u8 type;
0053             u8 code;
0054         } icmp;
0055     };
0056 };
0057 
0058 struct bnxt_tc_tunnel_key {
0059     struct bnxt_tc_l2_key   l2;
0060     struct bnxt_tc_l3_key   l3;
0061     struct bnxt_tc_l4_key   l4;
0062     __be32          id;
0063 };
0064 
0065 #define bnxt_eth_addr_key_mask_invalid(eth_addr, eth_addr_mask)     \
0066     ((is_wildcard(&(eth_addr)[0], ETH_ALEN) &&          \
0067      is_wildcard(&(eth_addr)[ETH_ALEN / 2], ETH_ALEN)) ||       \
0068     (is_wildcard(&(eth_addr_mask)[0], ETH_ALEN) &&          \
0069      is_wildcard(&(eth_addr_mask)[ETH_ALEN / 2], ETH_ALEN)))
0070 
0071 struct bnxt_tc_actions {
0072     u32             flags;
0073 #define BNXT_TC_ACTION_FLAG_FWD         BIT(0)
0074 #define BNXT_TC_ACTION_FLAG_FWD_VXLAN       BIT(1)
0075 #define BNXT_TC_ACTION_FLAG_PUSH_VLAN       BIT(3)
0076 #define BNXT_TC_ACTION_FLAG_POP_VLAN        BIT(4)
0077 #define BNXT_TC_ACTION_FLAG_DROP        BIT(5)
0078 #define BNXT_TC_ACTION_FLAG_TUNNEL_ENCAP    BIT(6)
0079 #define BNXT_TC_ACTION_FLAG_TUNNEL_DECAP    BIT(7)
0080 #define BNXT_TC_ACTION_FLAG_L2_REWRITE      BIT(8)
0081 #define BNXT_TC_ACTION_FLAG_NAT_XLATE       BIT(9)
0082 
0083     u16             dst_fid;
0084     struct net_device       *dst_dev;
0085     __be16              push_vlan_tpid;
0086     __be16              push_vlan_tci;
0087 
0088     /* tunnel encap */
0089     struct ip_tunnel_key        tun_encap_key;
0090 #define PEDIT_OFFSET_SMAC_LAST_4_BYTES      0x8
0091     __be16              l2_rewrite_dmac[3];
0092     __be16              l2_rewrite_smac[3];
0093     struct {
0094         bool src_xlate;  /* true => translate src,
0095                   * false => translate dst
0096                   * Mutually exclusive, i.e cannot set both
0097                   */
0098         bool l3_is_ipv4; /* false means L3 is ipv6 */
0099         struct bnxt_tc_l3_key l3;
0100         struct bnxt_tc_l4_key l4;
0101     } nat;
0102 };
0103 
0104 struct bnxt_tc_flow {
0105     u32             flags;
0106 #define BNXT_TC_FLOW_FLAGS_ETH_ADDRS        BIT(1)
0107 #define BNXT_TC_FLOW_FLAGS_IPV4_ADDRS       BIT(2)
0108 #define BNXT_TC_FLOW_FLAGS_IPV6_ADDRS       BIT(3)
0109 #define BNXT_TC_FLOW_FLAGS_PORTS        BIT(4)
0110 #define BNXT_TC_FLOW_FLAGS_ICMP         BIT(5)
0111 #define BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS   BIT(6)
0112 #define BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS  BIT(7)
0113 #define BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS  BIT(8)
0114 #define BNXT_TC_FLOW_FLAGS_TUNL_PORTS       BIT(9)
0115 #define BNXT_TC_FLOW_FLAGS_TUNL_ID      BIT(10)
0116 #define BNXT_TC_FLOW_FLAGS_TUNNEL   (BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS | \
0117                      BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS | \
0118                      BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS |\
0119                      BNXT_TC_FLOW_FLAGS_TUNL_PORTS |\
0120                      BNXT_TC_FLOW_FLAGS_TUNL_ID)
0121 
0122     /* flow applicable to pkts ingressing on this fid */
0123     u16             src_fid;
0124     struct bnxt_tc_l2_key       l2_key;
0125     struct bnxt_tc_l2_key       l2_mask;
0126     struct bnxt_tc_l3_key       l3_key;
0127     struct bnxt_tc_l3_key       l3_mask;
0128     struct bnxt_tc_l4_key       l4_key;
0129     struct bnxt_tc_l4_key       l4_mask;
0130     struct ip_tunnel_key        tun_key;
0131     struct ip_tunnel_key        tun_mask;
0132 
0133     struct bnxt_tc_actions      actions;
0134 
0135     /* updated stats accounting for hw-counter wrap-around */
0136     struct bnxt_tc_flow_stats   stats;
0137     /* previous snap-shot of stats */
0138     struct bnxt_tc_flow_stats   prev_stats;
0139     unsigned long           lastused; /* jiffies */
0140     /* for calculating delta from prev_stats and
0141      * updating prev_stats atomically.
0142      */
0143     spinlock_t          stats_lock;
0144 };
0145 
0146 /* Tunnel encap/decap hash table
0147  * This table is used to maintain a list of flows that use
0148  * the same tunnel encap/decap params (ip_daddrs, vni, udp_dport)
0149  * and the FW returned handle.
0150  * A separate table is maintained for encap and decap
0151  */
0152 struct bnxt_tc_tunnel_node {
0153     struct ip_tunnel_key        key;
0154     struct rhash_head       node;
0155 
0156     /* tunnel l2 info */
0157     struct bnxt_tc_l2_key       l2_info;
0158 
0159 #define INVALID_TUNNEL_HANDLE       cpu_to_le32(0xffffffff)
0160     /* tunnel handle returned by FW */
0161     __le32              tunnel_handle;
0162 
0163     u32             refcount;
0164     struct rcu_head         rcu;
0165 };
0166 
0167 /* L2 hash table
0168  * The same data-struct is used for L2-flow table and L2-tunnel table.
0169  * The L2 part of a flow or tunnel is stored in a hash table.
0170  * A flow that shares the same L2 key/mask with an
0171  * already existing flow/tunnel must refer to it's flow handle or
0172  * decap_filter_id respectively.
0173  */
0174 struct bnxt_tc_l2_node {
0175     /* hash key: first 16b of key */
0176 #define BNXT_TC_L2_KEY_LEN          16
0177     struct bnxt_tc_l2_key   key;
0178     struct rhash_head   node;
0179 
0180     /* a linked list of flows that share the same l2 key */
0181     struct list_head    common_l2_flows;
0182 
0183     /* number of flows/tunnels sharing the l2 key */
0184     u16         refcount;
0185 
0186     struct rcu_head     rcu;
0187 };
0188 
0189 struct bnxt_tc_flow_node {
0190     /* hash key: provided by TC */
0191     unsigned long           cookie;
0192     struct rhash_head       node;
0193 
0194     struct bnxt_tc_flow     flow;
0195 
0196     __le64              ext_flow_handle;
0197     __le16              flow_handle;
0198     __le32              flow_id;
0199 
0200     /* L2 node in l2 hashtable that shares flow's l2 key */
0201     struct bnxt_tc_l2_node      *l2_node;
0202     /* for the shared_flows list maintained in l2_node */
0203     struct list_head        l2_list_node;
0204 
0205     /* tunnel encap related */
0206     struct bnxt_tc_tunnel_node  *encap_node;
0207 
0208     /* tunnel decap related */
0209     struct bnxt_tc_tunnel_node  *decap_node;
0210     /* L2 node in tunnel-l2 hashtable that shares flow's tunnel l2 key */
0211     struct bnxt_tc_l2_node      *decap_l2_node;
0212     /* for the shared_flows list maintained in tunnel decap l2_node */
0213     struct list_head        decap_l2_list_node;
0214 
0215     struct rcu_head         rcu;
0216 };
0217 
0218 int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
0219              struct flow_cls_offload *cls_flower);
0220 int bnxt_init_tc(struct bnxt *bp);
0221 void bnxt_shutdown_tc(struct bnxt *bp);
0222 void bnxt_tc_flow_stats_work(struct bnxt *bp);
0223 
0224 static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
0225 {
0226     return bp->tc_info && bp->tc_info->enabled;
0227 }
0228 
0229 #else /* CONFIG_BNXT_FLOWER_OFFLOAD */
0230 
0231 static inline int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
0232                        struct flow_cls_offload *cls_flower)
0233 {
0234     return -EOPNOTSUPP;
0235 }
0236 
0237 static inline int bnxt_init_tc(struct bnxt *bp)
0238 {
0239     return 0;
0240 }
0241 
0242 static inline void bnxt_shutdown_tc(struct bnxt *bp)
0243 {
0244 }
0245 
0246 static inline void bnxt_tc_flow_stats_work(struct bnxt *bp)
0247 {
0248 }
0249 
0250 static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
0251 {
0252     return false;
0253 }
0254 #endif /* CONFIG_BNXT_FLOWER_OFFLOAD */
0255 #endif /* BNXT_TC_H */