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.
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 {
22 __be16 inner_vlan_tpid;
23 __be16 inner_vlan_tci;
31 struct bnxt_tc_l3_key {
38 struct in6_addr daddr;
39 struct in6_addr saddr;
44 struct bnxt_tc_l4_key {
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;
65 struct bnxt_tc_actions {
67 #define BNXT_TC_ACTION_FLAG_FWD BIT(0)
68 #define BNXT_TC_ACTION_FLAG_FWD_VXLAN BIT(1)
69 #define BNXT_TC_ACTION_FLAG_PUSH_VLAN BIT(3)
70 #define BNXT_TC_ACTION_FLAG_POP_VLAN BIT(4)
71 #define BNXT_TC_ACTION_FLAG_DROP BIT(5)
72 #define BNXT_TC_ACTION_FLAG_TUNNEL_ENCAP BIT(6)
73 #define BNXT_TC_ACTION_FLAG_TUNNEL_DECAP BIT(7)
76 struct net_device *dst_dev;
77 __be16 push_vlan_tpid;
81 struct ip_tunnel_key tun_encap_key;
86 #define BNXT_TC_FLOW_FLAGS_ETH_ADDRS BIT(1)
87 #define BNXT_TC_FLOW_FLAGS_IPV4_ADDRS BIT(2)
88 #define BNXT_TC_FLOW_FLAGS_IPV6_ADDRS BIT(3)
89 #define BNXT_TC_FLOW_FLAGS_PORTS BIT(4)
90 #define BNXT_TC_FLOW_FLAGS_ICMP BIT(5)
91 #define BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS BIT(6)
92 #define BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS BIT(7)
93 #define BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS BIT(8)
94 #define BNXT_TC_FLOW_FLAGS_TUNL_PORTS BIT(9)
95 #define BNXT_TC_FLOW_FLAGS_TUNL_ID BIT(10)
96 #define BNXT_TC_FLOW_FLAGS_TUNNEL (BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS | \
97 BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS | \
98 BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS |\
99 BNXT_TC_FLOW_FLAGS_TUNL_PORTS |\
100 BNXT_TC_FLOW_FLAGS_TUNL_ID)
102 /* flow applicable to pkts ingressing on this fid */
104 struct bnxt_tc_l2_key l2_key;
105 struct bnxt_tc_l2_key l2_mask;
106 struct bnxt_tc_l3_key l3_key;
107 struct bnxt_tc_l3_key l3_mask;
108 struct bnxt_tc_l4_key l4_key;
109 struct bnxt_tc_l4_key l4_mask;
110 struct ip_tunnel_key tun_key;
111 struct ip_tunnel_key tun_mask;
113 struct bnxt_tc_actions actions;
115 /* updated stats accounting for hw-counter wrap-around */
116 struct bnxt_tc_flow_stats stats;
117 /* previous snap-shot of stats */
118 struct bnxt_tc_flow_stats prev_stats;
119 unsigned long lastused; /* jiffies */
120 /* for calculating delta from prev_stats and
121 * updating prev_stats atomically.
123 spinlock_t stats_lock;
126 /* Tunnel encap/decap hash table
127 * This table is used to maintain a list of flows that use
128 * the same tunnel encap/decap params (ip_daddrs, vni, udp_dport)
129 * and the FW returned handle.
130 * A separate table is maintained for encap and decap
132 struct bnxt_tc_tunnel_node {
133 struct ip_tunnel_key key;
134 struct rhash_head node;
137 struct bnxt_tc_l2_key l2_info;
139 #define INVALID_TUNNEL_HANDLE cpu_to_le32(0xffffffff)
140 /* tunnel handle returned by FW */
141 __le32 tunnel_handle;
148 * The same data-struct is used for L2-flow table and L2-tunnel table.
149 * The L2 part of a flow or tunnel is stored in a hash table.
150 * A flow that shares the same L2 key/mask with an
151 * already existing flow/tunnel must refer to it's flow handle or
152 * decap_filter_id respectively.
154 struct bnxt_tc_l2_node {
155 /* hash key: first 16b of key */
156 #define BNXT_TC_L2_KEY_LEN 16
157 struct bnxt_tc_l2_key key;
158 struct rhash_head node;
160 /* a linked list of flows that share the same l2 key */
161 struct list_head common_l2_flows;
163 /* number of flows/tunnels sharing the l2 key */
169 struct bnxt_tc_flow_node {
170 /* hash key: provided by TC */
171 unsigned long cookie;
172 struct rhash_head node;
174 struct bnxt_tc_flow flow;
176 __le64 ext_flow_handle;
180 /* L2 node in l2 hashtable that shares flow's l2 key */
181 struct bnxt_tc_l2_node *l2_node;
182 /* for the shared_flows list maintained in l2_node */
183 struct list_head l2_list_node;
185 /* tunnel encap related */
186 struct bnxt_tc_tunnel_node *encap_node;
188 /* tunnel decap related */
189 struct bnxt_tc_tunnel_node *decap_node;
190 /* L2 node in tunnel-l2 hashtable that shares flow's tunnel l2 key */
191 struct bnxt_tc_l2_node *decap_l2_node;
192 /* for the shared_flows list maintained in tunnel decap l2_node */
193 struct list_head decap_l2_list_node;
198 int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
199 struct flow_cls_offload *cls_flower);
200 int bnxt_init_tc(struct bnxt *bp);
201 void bnxt_shutdown_tc(struct bnxt *bp);
202 void bnxt_tc_flow_stats_work(struct bnxt *bp);
204 static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
206 return bp->tc_info && bp->tc_info->enabled;
209 #else /* CONFIG_BNXT_FLOWER_OFFLOAD */
211 static inline int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
212 struct flow_cls_offload *cls_flower)
217 static inline int bnxt_init_tc(struct bnxt *bp)
222 static inline void bnxt_shutdown_tc(struct bnxt *bp)
226 static inline void bnxt_tc_flow_stats_work(struct bnxt *bp)
230 static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
234 #endif /* CONFIG_BNXT_FLOWER_OFFLOAD */
235 #endif /* BNXT_TC_H */