treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / ethernet / broadcom / bnxt / bnxt_tc.h
blob10c62b09491484b313a79af9202f4301fd2f0cec
1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2017 Broadcom Limited
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 */
10 #ifndef BNXT_TC_H
11 #define BNXT_TC_H
13 #ifdef CONFIG_BNXT_FLOWER_OFFLOAD
15 #include <net/ip_tunnels.h>
17 /* Structs used for storing the filter/actions of the TC cmd.
19 struct bnxt_tc_l2_key {
20 u8 dmac[ETH_ALEN];
21 u8 smac[ETH_ALEN];
22 __be16 inner_vlan_tpid;
23 __be16 inner_vlan_tci;
24 __be16 ether_type;
25 u8 num_vlans;
26 u8 dir;
27 #define BNXT_DIR_RX 1
28 #define BNXT_DIR_TX 0
31 struct bnxt_tc_l3_key {
32 union {
33 struct {
34 struct in_addr daddr;
35 struct in_addr saddr;
36 } ipv4;
37 struct {
38 struct in6_addr daddr;
39 struct in6_addr saddr;
40 } ipv6;
44 struct bnxt_tc_l4_key {
45 u8 ip_proto;
46 union {
47 struct {
48 __be16 sport;
49 __be16 dport;
50 } ports;
51 struct {
52 u8 type;
53 u8 code;
54 } icmp;
58 struct bnxt_tc_tunnel_key {
59 struct bnxt_tc_l2_key l2;
60 struct bnxt_tc_l3_key l3;
61 struct bnxt_tc_l4_key l4;
62 __be32 id;
65 #define bnxt_eth_addr_key_mask_invalid(eth_addr, eth_addr_mask) \
66 ((is_wildcard(&(eth_addr)[0], ETH_ALEN) && \
67 is_wildcard(&(eth_addr)[ETH_ALEN / 2], ETH_ALEN)) || \
68 (is_wildcard(&(eth_addr_mask)[0], ETH_ALEN) && \
69 is_wildcard(&(eth_addr_mask)[ETH_ALEN / 2], ETH_ALEN)))
71 struct bnxt_tc_actions {
72 u32 flags;
73 #define BNXT_TC_ACTION_FLAG_FWD BIT(0)
74 #define BNXT_TC_ACTION_FLAG_FWD_VXLAN BIT(1)
75 #define BNXT_TC_ACTION_FLAG_PUSH_VLAN BIT(3)
76 #define BNXT_TC_ACTION_FLAG_POP_VLAN BIT(4)
77 #define BNXT_TC_ACTION_FLAG_DROP BIT(5)
78 #define BNXT_TC_ACTION_FLAG_TUNNEL_ENCAP BIT(6)
79 #define BNXT_TC_ACTION_FLAG_TUNNEL_DECAP BIT(7)
80 #define BNXT_TC_ACTION_FLAG_L2_REWRITE BIT(8)
81 #define BNXT_TC_ACTION_FLAG_NAT_XLATE BIT(9)
83 u16 dst_fid;
84 struct net_device *dst_dev;
85 __be16 push_vlan_tpid;
86 __be16 push_vlan_tci;
88 /* tunnel encap */
89 struct ip_tunnel_key tun_encap_key;
90 #define PEDIT_OFFSET_SMAC_LAST_4_BYTES 0x8
91 __be16 l2_rewrite_dmac[3];
92 __be16 l2_rewrite_smac[3];
93 struct {
94 bool src_xlate; /* true => translate src,
95 * false => translate dst
96 * Mutually exclusive, i.e cannot set both
98 bool l3_is_ipv4; /* false means L3 is ipv6 */
99 struct bnxt_tc_l3_key l3;
100 struct bnxt_tc_l4_key l4;
101 } nat;
104 struct bnxt_tc_flow {
105 u32 flags;
106 #define BNXT_TC_FLOW_FLAGS_ETH_ADDRS BIT(1)
107 #define BNXT_TC_FLOW_FLAGS_IPV4_ADDRS BIT(2)
108 #define BNXT_TC_FLOW_FLAGS_IPV6_ADDRS BIT(3)
109 #define BNXT_TC_FLOW_FLAGS_PORTS BIT(4)
110 #define BNXT_TC_FLOW_FLAGS_ICMP BIT(5)
111 #define BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS BIT(6)
112 #define BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS BIT(7)
113 #define BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS BIT(8)
114 #define BNXT_TC_FLOW_FLAGS_TUNL_PORTS BIT(9)
115 #define BNXT_TC_FLOW_FLAGS_TUNL_ID BIT(10)
116 #define BNXT_TC_FLOW_FLAGS_TUNNEL (BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS | \
117 BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS | \
118 BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS |\
119 BNXT_TC_FLOW_FLAGS_TUNL_PORTS |\
120 BNXT_TC_FLOW_FLAGS_TUNL_ID)
122 /* flow applicable to pkts ingressing on this fid */
123 u16 src_fid;
124 struct bnxt_tc_l2_key l2_key;
125 struct bnxt_tc_l2_key l2_mask;
126 struct bnxt_tc_l3_key l3_key;
127 struct bnxt_tc_l3_key l3_mask;
128 struct bnxt_tc_l4_key l4_key;
129 struct bnxt_tc_l4_key l4_mask;
130 struct ip_tunnel_key tun_key;
131 struct ip_tunnel_key tun_mask;
133 struct bnxt_tc_actions actions;
135 /* updated stats accounting for hw-counter wrap-around */
136 struct bnxt_tc_flow_stats stats;
137 /* previous snap-shot of stats */
138 struct bnxt_tc_flow_stats prev_stats;
139 unsigned long lastused; /* jiffies */
140 /* for calculating delta from prev_stats and
141 * updating prev_stats atomically.
143 spinlock_t stats_lock;
146 /* Tunnel encap/decap hash table
147 * This table is used to maintain a list of flows that use
148 * the same tunnel encap/decap params (ip_daddrs, vni, udp_dport)
149 * and the FW returned handle.
150 * A separate table is maintained for encap and decap
152 struct bnxt_tc_tunnel_node {
153 struct ip_tunnel_key key;
154 struct rhash_head node;
156 /* tunnel l2 info */
157 struct bnxt_tc_l2_key l2_info;
159 #define INVALID_TUNNEL_HANDLE cpu_to_le32(0xffffffff)
160 /* tunnel handle returned by FW */
161 __le32 tunnel_handle;
163 u32 refcount;
164 struct rcu_head rcu;
167 /* L2 hash table
168 * The same data-struct is used for L2-flow table and L2-tunnel table.
169 * The L2 part of a flow or tunnel is stored in a hash table.
170 * A flow that shares the same L2 key/mask with an
171 * already existing flow/tunnel must refer to it's flow handle or
172 * decap_filter_id respectively.
174 struct bnxt_tc_l2_node {
175 /* hash key: first 16b of key */
176 #define BNXT_TC_L2_KEY_LEN 16
177 struct bnxt_tc_l2_key key;
178 struct rhash_head node;
180 /* a linked list of flows that share the same l2 key */
181 struct list_head common_l2_flows;
183 /* number of flows/tunnels sharing the l2 key */
184 u16 refcount;
186 struct rcu_head rcu;
189 struct bnxt_tc_flow_node {
190 /* hash key: provided by TC */
191 unsigned long cookie;
192 struct rhash_head node;
194 struct bnxt_tc_flow flow;
196 __le64 ext_flow_handle;
197 __le16 flow_handle;
198 __le32 flow_id;
200 /* L2 node in l2 hashtable that shares flow's l2 key */
201 struct bnxt_tc_l2_node *l2_node;
202 /* for the shared_flows list maintained in l2_node */
203 struct list_head l2_list_node;
205 /* tunnel encap related */
206 struct bnxt_tc_tunnel_node *encap_node;
208 /* tunnel decap related */
209 struct bnxt_tc_tunnel_node *decap_node;
210 /* L2 node in tunnel-l2 hashtable that shares flow's tunnel l2 key */
211 struct bnxt_tc_l2_node *decap_l2_node;
212 /* for the shared_flows list maintained in tunnel decap l2_node */
213 struct list_head decap_l2_list_node;
215 struct rcu_head rcu;
218 int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
219 struct flow_cls_offload *cls_flower);
220 int bnxt_init_tc(struct bnxt *bp);
221 void bnxt_shutdown_tc(struct bnxt *bp);
222 void bnxt_tc_flow_stats_work(struct bnxt *bp);
224 static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
226 return bp->tc_info && bp->tc_info->enabled;
229 #else /* CONFIG_BNXT_FLOWER_OFFLOAD */
231 static inline int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
232 struct flow_cls_offload *cls_flower)
234 return -EOPNOTSUPP;
237 static inline int bnxt_init_tc(struct bnxt *bp)
239 return 0;
242 static inline void bnxt_shutdown_tc(struct bnxt *bp)
246 static inline void bnxt_tc_flow_stats_work(struct bnxt *bp)
250 static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
252 return false;
254 #endif /* CONFIG_BNXT_FLOWER_OFFLOAD */
255 #endif /* BNXT_TC_H */