12ae7408fSSathya Perla /* Broadcom NetXtreme-C/E network driver.
22ae7408fSSathya Perla *
32ae7408fSSathya Perla * Copyright (c) 2017 Broadcom Limited
42ae7408fSSathya Perla *
52ae7408fSSathya Perla * This program is free software; you can redistribute it and/or modify
62ae7408fSSathya Perla * it under the terms of the GNU General Public License as published by
72ae7408fSSathya Perla * the Free Software Foundation.
82ae7408fSSathya Perla */
92ae7408fSSathya Perla
102ae7408fSSathya Perla #ifndef BNXT_TC_H
112ae7408fSSathya Perla #define BNXT_TC_H
122ae7408fSSathya Perla
132ae7408fSSathya Perla #ifdef CONFIG_BNXT_FLOWER_OFFLOAD
142ae7408fSSathya Perla
158c95f773SSathya Perla #include <net/ip_tunnels.h>
168c95f773SSathya Perla
172ae7408fSSathya Perla /* Structs used for storing the filter/actions of the TC cmd.
182ae7408fSSathya Perla */
192ae7408fSSathya Perla struct bnxt_tc_l2_key {
202ae7408fSSathya Perla u8 dmac[ETH_ALEN];
212ae7408fSSathya Perla u8 smac[ETH_ALEN];
222ae7408fSSathya Perla __be16 inner_vlan_tpid;
232ae7408fSSathya Perla __be16 inner_vlan_tci;
242ae7408fSSathya Perla __be16 ether_type;
252ae7408fSSathya Perla u8 num_vlans;
269bf46566SSomnath Kotur u8 dir;
279bf46566SSomnath Kotur #define BNXT_DIR_RX 1
289bf46566SSomnath Kotur #define BNXT_DIR_TX 0
292ae7408fSSathya Perla };
302ae7408fSSathya Perla
312ae7408fSSathya Perla struct bnxt_tc_l3_key {
322ae7408fSSathya Perla union {
332ae7408fSSathya Perla struct {
342ae7408fSSathya Perla struct in_addr daddr;
352ae7408fSSathya Perla struct in_addr saddr;
362ae7408fSSathya Perla } ipv4;
372ae7408fSSathya Perla struct {
382ae7408fSSathya Perla struct in6_addr daddr;
392ae7408fSSathya Perla struct in6_addr saddr;
402ae7408fSSathya Perla } ipv6;
412ae7408fSSathya Perla };
422ae7408fSSathya Perla };
432ae7408fSSathya Perla
442ae7408fSSathya Perla struct bnxt_tc_l4_key {
452ae7408fSSathya Perla u8 ip_proto;
462ae7408fSSathya Perla union {
472ae7408fSSathya Perla struct {
482ae7408fSSathya Perla __be16 sport;
492ae7408fSSathya Perla __be16 dport;
502ae7408fSSathya Perla } ports;
512ae7408fSSathya Perla struct {
522ae7408fSSathya Perla u8 type;
532ae7408fSSathya Perla u8 code;
542ae7408fSSathya Perla } icmp;
552ae7408fSSathya Perla };
562ae7408fSSathya Perla };
572ae7408fSSathya Perla
588c95f773SSathya Perla struct bnxt_tc_tunnel_key {
598c95f773SSathya Perla struct bnxt_tc_l2_key l2;
608c95f773SSathya Perla struct bnxt_tc_l3_key l3;
618c95f773SSathya Perla struct bnxt_tc_l4_key l4;
628c95f773SSathya Perla __be32 id;
638c95f773SSathya Perla };
648c95f773SSathya Perla
6590f90624SVenkat Duvvuru #define bnxt_eth_addr_key_mask_invalid(eth_addr, eth_addr_mask) \
6690f90624SVenkat Duvvuru ((is_wildcard(&(eth_addr)[0], ETH_ALEN) && \
67*3128aad1SVenkat Duvvuru is_wildcard(&(eth_addr)[ETH_ALEN / 2], ETH_ALEN)) || \
6890f90624SVenkat Duvvuru (is_wildcard(&(eth_addr_mask)[0], ETH_ALEN) && \
69*3128aad1SVenkat Duvvuru is_wildcard(&(eth_addr_mask)[ETH_ALEN / 2], ETH_ALEN)))
7090f90624SVenkat Duvvuru
712ae7408fSSathya Perla struct bnxt_tc_actions {
722ae7408fSSathya Perla u32 flags;
732ae7408fSSathya Perla #define BNXT_TC_ACTION_FLAG_FWD BIT(0)
742ae7408fSSathya Perla #define BNXT_TC_ACTION_FLAG_FWD_VXLAN BIT(1)
752ae7408fSSathya Perla #define BNXT_TC_ACTION_FLAG_PUSH_VLAN BIT(3)
762ae7408fSSathya Perla #define BNXT_TC_ACTION_FLAG_POP_VLAN BIT(4)
772ae7408fSSathya Perla #define BNXT_TC_ACTION_FLAG_DROP BIT(5)
788c95f773SSathya Perla #define BNXT_TC_ACTION_FLAG_TUNNEL_ENCAP BIT(6)
798c95f773SSathya Perla #define BNXT_TC_ACTION_FLAG_TUNNEL_DECAP BIT(7)
8090f90624SVenkat Duvvuru #define BNXT_TC_ACTION_FLAG_L2_REWRITE BIT(8)
819b9eb518SSomnath Kotur #define BNXT_TC_ACTION_FLAG_NAT_XLATE BIT(9)
822ae7408fSSathya Perla
832ae7408fSSathya Perla u16 dst_fid;
842ae7408fSSathya Perla struct net_device *dst_dev;
852ae7408fSSathya Perla __be16 push_vlan_tpid;
862ae7408fSSathya Perla __be16 push_vlan_tci;
878c95f773SSathya Perla
888c95f773SSathya Perla /* tunnel encap */
898c95f773SSathya Perla struct ip_tunnel_key tun_encap_key;
9090f90624SVenkat Duvvuru #define PEDIT_OFFSET_SMAC_LAST_4_BYTES 0x8
9190f90624SVenkat Duvvuru __be16 l2_rewrite_dmac[3];
9290f90624SVenkat Duvvuru __be16 l2_rewrite_smac[3];
939b9eb518SSomnath Kotur struct {
949b9eb518SSomnath Kotur bool src_xlate; /* true => translate src,
959b9eb518SSomnath Kotur * false => translate dst
969b9eb518SSomnath Kotur * Mutually exclusive, i.e cannot set both
979b9eb518SSomnath Kotur */
989b9eb518SSomnath Kotur bool l3_is_ipv4; /* false means L3 is ipv6 */
999b9eb518SSomnath Kotur struct bnxt_tc_l3_key l3;
1009b9eb518SSomnath Kotur struct bnxt_tc_l4_key l4;
1019b9eb518SSomnath Kotur } nat;
1022ae7408fSSathya Perla };
1032ae7408fSSathya Perla
1042ae7408fSSathya Perla struct bnxt_tc_flow {
1052ae7408fSSathya Perla u32 flags;
1062ae7408fSSathya Perla #define BNXT_TC_FLOW_FLAGS_ETH_ADDRS BIT(1)
1072ae7408fSSathya Perla #define BNXT_TC_FLOW_FLAGS_IPV4_ADDRS BIT(2)
1082ae7408fSSathya Perla #define BNXT_TC_FLOW_FLAGS_IPV6_ADDRS BIT(3)
1092ae7408fSSathya Perla #define BNXT_TC_FLOW_FLAGS_PORTS BIT(4)
1102ae7408fSSathya Perla #define BNXT_TC_FLOW_FLAGS_ICMP BIT(5)
1118c95f773SSathya Perla #define BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS BIT(6)
1128c95f773SSathya Perla #define BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS BIT(7)
1138c95f773SSathya Perla #define BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS BIT(8)
1148c95f773SSathya Perla #define BNXT_TC_FLOW_FLAGS_TUNL_PORTS BIT(9)
1158c95f773SSathya Perla #define BNXT_TC_FLOW_FLAGS_TUNL_ID BIT(10)
1168c95f773SSathya Perla #define BNXT_TC_FLOW_FLAGS_TUNNEL (BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS | \
1178c95f773SSathya Perla BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS | \
1188c95f773SSathya Perla BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS |\
1198c95f773SSathya Perla BNXT_TC_FLOW_FLAGS_TUNL_PORTS |\
1208c95f773SSathya Perla BNXT_TC_FLOW_FLAGS_TUNL_ID)
1212ae7408fSSathya Perla
1222ae7408fSSathya Perla /* flow applicable to pkts ingressing on this fid */
1232ae7408fSSathya Perla u16 src_fid;
1242ae7408fSSathya Perla struct bnxt_tc_l2_key l2_key;
1252ae7408fSSathya Perla struct bnxt_tc_l2_key l2_mask;
1262ae7408fSSathya Perla struct bnxt_tc_l3_key l3_key;
1272ae7408fSSathya Perla struct bnxt_tc_l3_key l3_mask;
1282ae7408fSSathya Perla struct bnxt_tc_l4_key l4_key;
1292ae7408fSSathya Perla struct bnxt_tc_l4_key l4_mask;
1308c95f773SSathya Perla struct ip_tunnel_key tun_key;
1318c95f773SSathya Perla struct ip_tunnel_key tun_mask;
1322ae7408fSSathya Perla
1332ae7408fSSathya Perla struct bnxt_tc_actions actions;
1342ae7408fSSathya Perla
1352ae7408fSSathya Perla /* updated stats accounting for hw-counter wrap-around */
1362ae7408fSSathya Perla struct bnxt_tc_flow_stats stats;
1372ae7408fSSathya Perla /* previous snap-shot of stats */
1382ae7408fSSathya Perla struct bnxt_tc_flow_stats prev_stats;
1392ae7408fSSathya Perla unsigned long lastused; /* jiffies */
1405a84acbeSSathya Perla /* for calculating delta from prev_stats and
1415a84acbeSSathya Perla * updating prev_stats atomically.
1425a84acbeSSathya Perla */
1435a84acbeSSathya Perla spinlock_t stats_lock;
1442ae7408fSSathya Perla };
1452ae7408fSSathya Perla
1468c95f773SSathya Perla /* Tunnel encap/decap hash table
1478c95f773SSathya Perla * This table is used to maintain a list of flows that use
1488c95f773SSathya Perla * the same tunnel encap/decap params (ip_daddrs, vni, udp_dport)
1498c95f773SSathya Perla * and the FW returned handle.
1508c95f773SSathya Perla * A separate table is maintained for encap and decap
1518c95f773SSathya Perla */
1528c95f773SSathya Perla struct bnxt_tc_tunnel_node {
1538c95f773SSathya Perla struct ip_tunnel_key key;
1548c95f773SSathya Perla struct rhash_head node;
1558c95f773SSathya Perla
1568c95f773SSathya Perla /* tunnel l2 info */
1578c95f773SSathya Perla struct bnxt_tc_l2_key l2_info;
1588c95f773SSathya Perla
1598c95f773SSathya Perla #define INVALID_TUNNEL_HANDLE cpu_to_le32(0xffffffff)
1608c95f773SSathya Perla /* tunnel handle returned by FW */
1618c95f773SSathya Perla __le32 tunnel_handle;
1628c95f773SSathya Perla
1638c95f773SSathya Perla u32 refcount;
1648c95f773SSathya Perla struct rcu_head rcu;
1658c95f773SSathya Perla };
1668c95f773SSathya Perla
1672ae7408fSSathya Perla /* L2 hash table
1688c95f773SSathya Perla * The same data-struct is used for L2-flow table and L2-tunnel table.
1698c95f773SSathya Perla * The L2 part of a flow or tunnel is stored in a hash table.
1702ae7408fSSathya Perla * A flow that shares the same L2 key/mask with an
1718c95f773SSathya Perla * already existing flow/tunnel must refer to it's flow handle or
1728c95f773SSathya Perla * decap_filter_id respectively.
1732ae7408fSSathya Perla */
1742ae7408fSSathya Perla struct bnxt_tc_l2_node {
1752ae7408fSSathya Perla /* hash key: first 16b of key */
1762ae7408fSSathya Perla #define BNXT_TC_L2_KEY_LEN 16
1772ae7408fSSathya Perla struct bnxt_tc_l2_key key;
1782ae7408fSSathya Perla struct rhash_head node;
1792ae7408fSSathya Perla
1802ae7408fSSathya Perla /* a linked list of flows that share the same l2 key */
1812ae7408fSSathya Perla struct list_head common_l2_flows;
1822ae7408fSSathya Perla
1838c95f773SSathya Perla /* number of flows/tunnels sharing the l2 key */
1842ae7408fSSathya Perla u16 refcount;
1852ae7408fSSathya Perla
1862ae7408fSSathya Perla struct rcu_head rcu;
1872ae7408fSSathya Perla };
1882ae7408fSSathya Perla
1892ae7408fSSathya Perla struct bnxt_tc_flow_node {
1902ae7408fSSathya Perla /* hash key: provided by TC */
1912ae7408fSSathya Perla unsigned long cookie;
1922ae7408fSSathya Perla struct rhash_head node;
1932ae7408fSSathya Perla
1942ae7408fSSathya Perla struct bnxt_tc_flow flow;
1952ae7408fSSathya Perla
196abd43a13SVenkat Duvvuru __le64 ext_flow_handle;
1972ae7408fSSathya Perla __le16 flow_handle;
198abd43a13SVenkat Duvvuru __le32 flow_id;
1992ae7408fSSathya Perla
2002ae7408fSSathya Perla /* L2 node in l2 hashtable that shares flow's l2 key */
2012ae7408fSSathya Perla struct bnxt_tc_l2_node *l2_node;
2022ae7408fSSathya Perla /* for the shared_flows list maintained in l2_node */
2032ae7408fSSathya Perla struct list_head l2_list_node;
2042ae7408fSSathya Perla
2058c95f773SSathya Perla /* tunnel encap related */
2068c95f773SSathya Perla struct bnxt_tc_tunnel_node *encap_node;
2078c95f773SSathya Perla
2088c95f773SSathya Perla /* tunnel decap related */
2098c95f773SSathya Perla struct bnxt_tc_tunnel_node *decap_node;
2108c95f773SSathya Perla /* L2 node in tunnel-l2 hashtable that shares flow's tunnel l2 key */
2118c95f773SSathya Perla struct bnxt_tc_l2_node *decap_l2_node;
2128c95f773SSathya Perla /* for the shared_flows list maintained in tunnel decap l2_node */
2138c95f773SSathya Perla struct list_head decap_l2_list_node;
2148c95f773SSathya Perla
2152ae7408fSSathya Perla struct rcu_head rcu;
2162ae7408fSSathya Perla };
2172ae7408fSSathya Perla
2182ae7408fSSathya Perla int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
219f9e30088SPablo Neira Ayuso struct flow_cls_offload *cls_flower);
2202ae7408fSSathya Perla int bnxt_init_tc(struct bnxt *bp);
2212ae7408fSSathya Perla void bnxt_shutdown_tc(struct bnxt *bp);
2225a84acbeSSathya Perla void bnxt_tc_flow_stats_work(struct bnxt *bp);
2235a84acbeSSathya Perla
bnxt_tc_flower_enabled(struct bnxt * bp)2245a84acbeSSathya Perla static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
2255a84acbeSSathya Perla {
226cd66358eSSathya Perla return bp->tc_info && bp->tc_info->enabled;
2275a84acbeSSathya Perla }
2282ae7408fSSathya Perla
2292ae7408fSSathya Perla #else /* CONFIG_BNXT_FLOWER_OFFLOAD */
2302ae7408fSSathya Perla
bnxt_tc_setup_flower(struct bnxt * bp,u16 src_fid,struct flow_cls_offload * cls_flower)2312ae7408fSSathya Perla static inline int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
232f9e30088SPablo Neira Ayuso struct flow_cls_offload *cls_flower)
2332ae7408fSSathya Perla {
2342ae7408fSSathya Perla return -EOPNOTSUPP;
2352ae7408fSSathya Perla }
2362ae7408fSSathya Perla
bnxt_init_tc(struct bnxt * bp)2372ae7408fSSathya Perla static inline int bnxt_init_tc(struct bnxt *bp)
2382ae7408fSSathya Perla {
2392ae7408fSSathya Perla return 0;
2402ae7408fSSathya Perla }
2412ae7408fSSathya Perla
bnxt_shutdown_tc(struct bnxt * bp)2422ae7408fSSathya Perla static inline void bnxt_shutdown_tc(struct bnxt *bp)
2432ae7408fSSathya Perla {
2442ae7408fSSathya Perla }
2455a84acbeSSathya Perla
bnxt_tc_flow_stats_work(struct bnxt * bp)2465a84acbeSSathya Perla static inline void bnxt_tc_flow_stats_work(struct bnxt *bp)
2475a84acbeSSathya Perla {
2485a84acbeSSathya Perla }
2495a84acbeSSathya Perla
bnxt_tc_flower_enabled(struct bnxt * bp)2505a84acbeSSathya Perla static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
2515a84acbeSSathya Perla {
2525a84acbeSSathya Perla return false;
2535a84acbeSSathya Perla }
2542ae7408fSSathya Perla #endif /* CONFIG_BNXT_FLOWER_OFFLOAD */
2552ae7408fSSathya Perla #endif /* BNXT_TC_H */
256