xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/netronome/nfp/flower/main.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2*4882a593Smuzhiyun /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #ifndef __NFP_FLOWER_H__
5*4882a593Smuzhiyun #define __NFP_FLOWER_H__ 1
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include "cmsg.h"
8*4882a593Smuzhiyun #include "../nfp_net.h"
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/circ_buf.h>
11*4882a593Smuzhiyun #include <linux/hashtable.h>
12*4882a593Smuzhiyun #include <linux/rhashtable.h>
13*4882a593Smuzhiyun #include <linux/time64.h>
14*4882a593Smuzhiyun #include <linux/types.h>
15*4882a593Smuzhiyun #include <net/pkt_cls.h>
16*4882a593Smuzhiyun #include <net/tcp.h>
17*4882a593Smuzhiyun #include <linux/workqueue.h>
18*4882a593Smuzhiyun #include <linux/idr.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun struct nfp_fl_pre_lag;
21*4882a593Smuzhiyun struct net_device;
22*4882a593Smuzhiyun struct nfp_app;
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define NFP_FL_STAT_ID_MU_NUM		GENMASK(31, 22)
25*4882a593Smuzhiyun #define NFP_FL_STAT_ID_STAT		GENMASK(21, 0)
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define NFP_FL_STATS_ELEM_RS		sizeof_field(struct nfp_fl_stats_id, \
28*4882a593Smuzhiyun 						     init_unalloc)
29*4882a593Smuzhiyun #define NFP_FLOWER_MASK_ENTRY_RS	256
30*4882a593Smuzhiyun #define NFP_FLOWER_MASK_ELEMENT_RS	1
31*4882a593Smuzhiyun #define NFP_FLOWER_MASK_HASH_BITS	10
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define NFP_FLOWER_KEY_MAX_LW		32
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #define NFP_FL_META_FLAG_MANAGE_MASK	BIT(7)
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #define NFP_FL_MASK_REUSE_TIME_NS	40000
38*4882a593Smuzhiyun #define NFP_FL_MASK_ID_LOCATION		1
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* Extra features bitmap. */
41*4882a593Smuzhiyun #define NFP_FL_FEATS_GENEVE		BIT(0)
42*4882a593Smuzhiyun #define NFP_FL_NBI_MTU_SETTING		BIT(1)
43*4882a593Smuzhiyun #define NFP_FL_FEATS_GENEVE_OPT		BIT(2)
44*4882a593Smuzhiyun #define NFP_FL_FEATS_VLAN_PCP		BIT(3)
45*4882a593Smuzhiyun #define NFP_FL_FEATS_VF_RLIM		BIT(4)
46*4882a593Smuzhiyun #define NFP_FL_FEATS_FLOW_MOD		BIT(5)
47*4882a593Smuzhiyun #define NFP_FL_FEATS_PRE_TUN_RULES	BIT(6)
48*4882a593Smuzhiyun #define NFP_FL_FEATS_IPV6_TUN		BIT(7)
49*4882a593Smuzhiyun #define NFP_FL_FEATS_VLAN_QINQ		BIT(8)
50*4882a593Smuzhiyun #define NFP_FL_FEATS_HOST_ACK		BIT(31)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define NFP_FL_ENABLE_FLOW_MERGE	BIT(0)
53*4882a593Smuzhiyun #define NFP_FL_ENABLE_LAG		BIT(1)
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #define NFP_FL_FEATS_HOST \
56*4882a593Smuzhiyun 	(NFP_FL_FEATS_GENEVE | \
57*4882a593Smuzhiyun 	NFP_FL_NBI_MTU_SETTING | \
58*4882a593Smuzhiyun 	NFP_FL_FEATS_GENEVE_OPT | \
59*4882a593Smuzhiyun 	NFP_FL_FEATS_VLAN_PCP | \
60*4882a593Smuzhiyun 	NFP_FL_FEATS_VF_RLIM | \
61*4882a593Smuzhiyun 	NFP_FL_FEATS_FLOW_MOD | \
62*4882a593Smuzhiyun 	NFP_FL_FEATS_PRE_TUN_RULES | \
63*4882a593Smuzhiyun 	NFP_FL_FEATS_IPV6_TUN | \
64*4882a593Smuzhiyun 	NFP_FL_FEATS_VLAN_QINQ)
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun struct nfp_fl_mask_id {
67*4882a593Smuzhiyun 	struct circ_buf mask_id_free_list;
68*4882a593Smuzhiyun 	ktime_t *last_used;
69*4882a593Smuzhiyun 	u8 init_unallocated;
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun struct nfp_fl_stats_id {
73*4882a593Smuzhiyun 	struct circ_buf free_list;
74*4882a593Smuzhiyun 	u32 init_unalloc;
75*4882a593Smuzhiyun 	u8 repeated_em_count;
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun  * struct nfp_fl_tunnel_offloads - priv data for tunnel offloads
80*4882a593Smuzhiyun  * @offloaded_macs:	Hashtable of the offloaded MAC addresses
81*4882a593Smuzhiyun  * @ipv4_off_list:	List of IPv4 addresses to offload
82*4882a593Smuzhiyun  * @ipv6_off_list:	List of IPv6 addresses to offload
83*4882a593Smuzhiyun  * @neigh_off_list_v4:	List of IPv4 neighbour offloads
84*4882a593Smuzhiyun  * @neigh_off_list_v6:	List of IPv6 neighbour offloads
85*4882a593Smuzhiyun  * @ipv4_off_lock:	Lock for the IPv4 address list
86*4882a593Smuzhiyun  * @ipv6_off_lock:	Lock for the IPv6 address list
87*4882a593Smuzhiyun  * @neigh_off_lock_v4:	Lock for the IPv4 neighbour address list
88*4882a593Smuzhiyun  * @neigh_off_lock_v6:	Lock for the IPv6 neighbour address list
89*4882a593Smuzhiyun  * @mac_off_ids:	IDA to manage id assignment for offloaded MACs
90*4882a593Smuzhiyun  * @neigh_nb:		Notifier to monitor neighbour state
91*4882a593Smuzhiyun  */
92*4882a593Smuzhiyun struct nfp_fl_tunnel_offloads {
93*4882a593Smuzhiyun 	struct rhashtable offloaded_macs;
94*4882a593Smuzhiyun 	struct list_head ipv4_off_list;
95*4882a593Smuzhiyun 	struct list_head ipv6_off_list;
96*4882a593Smuzhiyun 	struct list_head neigh_off_list_v4;
97*4882a593Smuzhiyun 	struct list_head neigh_off_list_v6;
98*4882a593Smuzhiyun 	struct mutex ipv4_off_lock;
99*4882a593Smuzhiyun 	struct mutex ipv6_off_lock;
100*4882a593Smuzhiyun 	spinlock_t neigh_off_lock_v4;
101*4882a593Smuzhiyun 	spinlock_t neigh_off_lock_v6;
102*4882a593Smuzhiyun 	struct ida mac_off_ids;
103*4882a593Smuzhiyun 	struct notifier_block neigh_nb;
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /**
107*4882a593Smuzhiyun  * struct nfp_mtu_conf - manage MTU setting
108*4882a593Smuzhiyun  * @portnum:		NFP port number of repr with requested MTU change
109*4882a593Smuzhiyun  * @requested_val:	MTU value requested for repr
110*4882a593Smuzhiyun  * @ack:		Received ack that MTU has been correctly set
111*4882a593Smuzhiyun  * @wait_q:		Wait queue for MTU acknowledgements
112*4882a593Smuzhiyun  * @lock:		Lock for setting/reading MTU variables
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun struct nfp_mtu_conf {
115*4882a593Smuzhiyun 	u32 portnum;
116*4882a593Smuzhiyun 	unsigned int requested_val;
117*4882a593Smuzhiyun 	bool ack;
118*4882a593Smuzhiyun 	wait_queue_head_t wait_q;
119*4882a593Smuzhiyun 	spinlock_t lock;
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /**
123*4882a593Smuzhiyun  * struct nfp_fl_lag - Flower APP priv data for link aggregation
124*4882a593Smuzhiyun  * @work:		Work queue for writing configs to the HW
125*4882a593Smuzhiyun  * @lock:		Lock to protect lag_group_list
126*4882a593Smuzhiyun  * @group_list:		List of all master/slave groups offloaded
127*4882a593Smuzhiyun  * @ida_handle:		IDA to handle group ids
128*4882a593Smuzhiyun  * @pkt_num:		Incremented for each config packet sent
129*4882a593Smuzhiyun  * @batch_ver:		Incremented for each batch of config packets
130*4882a593Smuzhiyun  * @global_inst:	Instance allocator for groups
131*4882a593Smuzhiyun  * @rst_cfg:		Marker to reset HW LAG config
132*4882a593Smuzhiyun  * @retrans_skbs:	Cmsgs that could not be processed by HW and require
133*4882a593Smuzhiyun  *			retransmission
134*4882a593Smuzhiyun  */
135*4882a593Smuzhiyun struct nfp_fl_lag {
136*4882a593Smuzhiyun 	struct delayed_work work;
137*4882a593Smuzhiyun 	struct mutex lock;
138*4882a593Smuzhiyun 	struct list_head group_list;
139*4882a593Smuzhiyun 	struct ida ida_handle;
140*4882a593Smuzhiyun 	unsigned int pkt_num;
141*4882a593Smuzhiyun 	unsigned int batch_ver;
142*4882a593Smuzhiyun 	u8 global_inst;
143*4882a593Smuzhiyun 	bool rst_cfg;
144*4882a593Smuzhiyun 	struct sk_buff_head retrans_skbs;
145*4882a593Smuzhiyun };
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun /**
148*4882a593Smuzhiyun  * struct nfp_fl_internal_ports - Flower APP priv data for additional ports
149*4882a593Smuzhiyun  * @port_ids:	Assignment of ids to any additional ports
150*4882a593Smuzhiyun  * @lock:	Lock for extra ports list
151*4882a593Smuzhiyun  */
152*4882a593Smuzhiyun struct nfp_fl_internal_ports {
153*4882a593Smuzhiyun 	struct idr port_ids;
154*4882a593Smuzhiyun 	spinlock_t lock;
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /**
158*4882a593Smuzhiyun  * struct nfp_flower_priv - Flower APP per-vNIC priv data
159*4882a593Smuzhiyun  * @app:		Back pointer to app
160*4882a593Smuzhiyun  * @nn:			Pointer to vNIC
161*4882a593Smuzhiyun  * @mask_id_seed:	Seed used for mask hash table
162*4882a593Smuzhiyun  * @flower_version:	HW version of flower
163*4882a593Smuzhiyun  * @flower_ext_feats:	Bitmap of extra features the HW supports
164*4882a593Smuzhiyun  * @flower_en_feats:	Bitmap of features enabled by HW
165*4882a593Smuzhiyun  * @stats_ids:		List of free stats ids
166*4882a593Smuzhiyun  * @mask_ids:		List of free mask ids
167*4882a593Smuzhiyun  * @mask_table:		Hash table used to store masks
168*4882a593Smuzhiyun  * @stats_ring_size:	Maximum number of allowed stats ids
169*4882a593Smuzhiyun  * @flow_table:		Hash table used to store flower rules
170*4882a593Smuzhiyun  * @stats:		Stored stats updates for flower rules
171*4882a593Smuzhiyun  * @stats_lock:		Lock for flower rule stats updates
172*4882a593Smuzhiyun  * @stats_ctx_table:	Hash table to map stats contexts to its flow rule
173*4882a593Smuzhiyun  * @cmsg_work:		Workqueue for control messages processing
174*4882a593Smuzhiyun  * @cmsg_skbs_high:	List of higher priority skbs for control message
175*4882a593Smuzhiyun  *			processing
176*4882a593Smuzhiyun  * @cmsg_skbs_low:	List of lower priority skbs for control message
177*4882a593Smuzhiyun  *			processing
178*4882a593Smuzhiyun  * @tun:		Tunnel offload data
179*4882a593Smuzhiyun  * @reify_replies:	atomically stores the number of replies received
180*4882a593Smuzhiyun  *			from firmware for repr reify
181*4882a593Smuzhiyun  * @reify_wait_queue:	wait queue for repr reify response counting
182*4882a593Smuzhiyun  * @mtu_conf:		Configuration of repr MTU value
183*4882a593Smuzhiyun  * @nfp_lag:		Link aggregation data block
184*4882a593Smuzhiyun  * @indr_block_cb_priv:	List of priv data passed to indirect block cbs
185*4882a593Smuzhiyun  * @non_repr_priv:	List of offloaded non-repr ports and their priv data
186*4882a593Smuzhiyun  * @active_mem_unit:	Current active memory unit for flower rules
187*4882a593Smuzhiyun  * @total_mem_units:	Total number of available memory units for flower rules
188*4882a593Smuzhiyun  * @internal_ports:	Internal port ids used in offloaded rules
189*4882a593Smuzhiyun  * @qos_stats_work:	Workqueue for qos stats processing
190*4882a593Smuzhiyun  * @qos_rate_limiters:	Current active qos rate limiters
191*4882a593Smuzhiyun  * @qos_stats_lock:	Lock on qos stats updates
192*4882a593Smuzhiyun  * @pre_tun_rule_cnt:	Number of pre-tunnel rules offloaded
193*4882a593Smuzhiyun  * @merge_table:	Hash table to store merged flows
194*4882a593Smuzhiyun  */
195*4882a593Smuzhiyun struct nfp_flower_priv {
196*4882a593Smuzhiyun 	struct nfp_app *app;
197*4882a593Smuzhiyun 	struct nfp_net *nn;
198*4882a593Smuzhiyun 	u32 mask_id_seed;
199*4882a593Smuzhiyun 	u64 flower_version;
200*4882a593Smuzhiyun 	u64 flower_ext_feats;
201*4882a593Smuzhiyun 	u8 flower_en_feats;
202*4882a593Smuzhiyun 	struct nfp_fl_stats_id stats_ids;
203*4882a593Smuzhiyun 	struct nfp_fl_mask_id mask_ids;
204*4882a593Smuzhiyun 	DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
205*4882a593Smuzhiyun 	u32 stats_ring_size;
206*4882a593Smuzhiyun 	struct rhashtable flow_table;
207*4882a593Smuzhiyun 	struct nfp_fl_stats *stats;
208*4882a593Smuzhiyun 	spinlock_t stats_lock; /* lock stats */
209*4882a593Smuzhiyun 	struct rhashtable stats_ctx_table;
210*4882a593Smuzhiyun 	struct work_struct cmsg_work;
211*4882a593Smuzhiyun 	struct sk_buff_head cmsg_skbs_high;
212*4882a593Smuzhiyun 	struct sk_buff_head cmsg_skbs_low;
213*4882a593Smuzhiyun 	struct nfp_fl_tunnel_offloads tun;
214*4882a593Smuzhiyun 	atomic_t reify_replies;
215*4882a593Smuzhiyun 	wait_queue_head_t reify_wait_queue;
216*4882a593Smuzhiyun 	struct nfp_mtu_conf mtu_conf;
217*4882a593Smuzhiyun 	struct nfp_fl_lag nfp_lag;
218*4882a593Smuzhiyun 	struct list_head indr_block_cb_priv;
219*4882a593Smuzhiyun 	struct list_head non_repr_priv;
220*4882a593Smuzhiyun 	unsigned int active_mem_unit;
221*4882a593Smuzhiyun 	unsigned int total_mem_units;
222*4882a593Smuzhiyun 	struct nfp_fl_internal_ports internal_ports;
223*4882a593Smuzhiyun 	struct delayed_work qos_stats_work;
224*4882a593Smuzhiyun 	unsigned int qos_rate_limiters;
225*4882a593Smuzhiyun 	spinlock_t qos_stats_lock; /* Protect the qos stats */
226*4882a593Smuzhiyun 	int pre_tun_rule_cnt;
227*4882a593Smuzhiyun 	struct rhashtable merge_table;
228*4882a593Smuzhiyun };
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /**
231*4882a593Smuzhiyun  * struct nfp_fl_qos - Flower APP priv data for quality of service
232*4882a593Smuzhiyun  * @netdev_port_id:	NFP port number of repr with qos info
233*4882a593Smuzhiyun  * @curr_stats:		Currently stored stats updates for qos info
234*4882a593Smuzhiyun  * @prev_stats:		Previously stored updates for qos info
235*4882a593Smuzhiyun  * @last_update:	Stored time when last stats were updated
236*4882a593Smuzhiyun  */
237*4882a593Smuzhiyun struct nfp_fl_qos {
238*4882a593Smuzhiyun 	u32 netdev_port_id;
239*4882a593Smuzhiyun 	struct nfp_stat_pair curr_stats;
240*4882a593Smuzhiyun 	struct nfp_stat_pair prev_stats;
241*4882a593Smuzhiyun 	u64 last_update;
242*4882a593Smuzhiyun };
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun /**
245*4882a593Smuzhiyun  * struct nfp_flower_repr_priv - Flower APP per-repr priv data
246*4882a593Smuzhiyun  * @nfp_repr:		Back pointer to nfp_repr
247*4882a593Smuzhiyun  * @lag_port_flags:	Extended port flags to record lag state of repr
248*4882a593Smuzhiyun  * @mac_offloaded:	Flag indicating a MAC address is offloaded for repr
249*4882a593Smuzhiyun  * @offloaded_mac_addr:	MAC address that has been offloaded for repr
250*4882a593Smuzhiyun  * @block_shared:	Flag indicating if offload applies to shared blocks
251*4882a593Smuzhiyun  * @mac_list:		List entry of reprs that share the same offloaded MAC
252*4882a593Smuzhiyun  * @qos_table:		Stored info on filters implementing qos
253*4882a593Smuzhiyun  * @on_bridge:		Indicates if the repr is attached to a bridge
254*4882a593Smuzhiyun  */
255*4882a593Smuzhiyun struct nfp_flower_repr_priv {
256*4882a593Smuzhiyun 	struct nfp_repr *nfp_repr;
257*4882a593Smuzhiyun 	unsigned long lag_port_flags;
258*4882a593Smuzhiyun 	bool mac_offloaded;
259*4882a593Smuzhiyun 	u8 offloaded_mac_addr[ETH_ALEN];
260*4882a593Smuzhiyun 	bool block_shared;
261*4882a593Smuzhiyun 	struct list_head mac_list;
262*4882a593Smuzhiyun 	struct nfp_fl_qos qos_table;
263*4882a593Smuzhiyun 	bool on_bridge;
264*4882a593Smuzhiyun };
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun /**
267*4882a593Smuzhiyun  * struct nfp_flower_non_repr_priv - Priv data for non-repr offloaded ports
268*4882a593Smuzhiyun  * @list:		List entry of offloaded reprs
269*4882a593Smuzhiyun  * @netdev:		Pointer to non-repr net_device
270*4882a593Smuzhiyun  * @ref_count:		Number of references held for this priv data
271*4882a593Smuzhiyun  * @mac_offloaded:	Flag indicating a MAC address is offloaded for device
272*4882a593Smuzhiyun  * @offloaded_mac_addr:	MAC address that has been offloaded for dev
273*4882a593Smuzhiyun  */
274*4882a593Smuzhiyun struct nfp_flower_non_repr_priv {
275*4882a593Smuzhiyun 	struct list_head list;
276*4882a593Smuzhiyun 	struct net_device *netdev;
277*4882a593Smuzhiyun 	int ref_count;
278*4882a593Smuzhiyun 	bool mac_offloaded;
279*4882a593Smuzhiyun 	u8 offloaded_mac_addr[ETH_ALEN];
280*4882a593Smuzhiyun };
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun struct nfp_fl_key_ls {
283*4882a593Smuzhiyun 	u32 key_layer_two;
284*4882a593Smuzhiyun 	u8 key_layer;
285*4882a593Smuzhiyun 	int key_size;
286*4882a593Smuzhiyun };
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun struct nfp_fl_rule_metadata {
289*4882a593Smuzhiyun 	u8 key_len;
290*4882a593Smuzhiyun 	u8 mask_len;
291*4882a593Smuzhiyun 	u8 act_len;
292*4882a593Smuzhiyun 	u8 flags;
293*4882a593Smuzhiyun 	__be32 host_ctx_id;
294*4882a593Smuzhiyun 	__be64 host_cookie __packed;
295*4882a593Smuzhiyun 	__be64 flow_version __packed;
296*4882a593Smuzhiyun 	__be32 shortcut;
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun struct nfp_fl_stats {
300*4882a593Smuzhiyun 	u64 pkts;
301*4882a593Smuzhiyun 	u64 bytes;
302*4882a593Smuzhiyun 	u64 used;
303*4882a593Smuzhiyun };
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun /**
306*4882a593Smuzhiyun  * struct nfp_ipv6_addr_entry - cached IPv6 addresses
307*4882a593Smuzhiyun  * @ipv6_addr:	IP address
308*4882a593Smuzhiyun  * @ref_count:	number of rules currently using this IP
309*4882a593Smuzhiyun  * @list:	list pointer
310*4882a593Smuzhiyun  */
311*4882a593Smuzhiyun struct nfp_ipv6_addr_entry {
312*4882a593Smuzhiyun 	struct in6_addr ipv6_addr;
313*4882a593Smuzhiyun 	int ref_count;
314*4882a593Smuzhiyun 	struct list_head list;
315*4882a593Smuzhiyun };
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun struct nfp_fl_payload {
318*4882a593Smuzhiyun 	struct nfp_fl_rule_metadata meta;
319*4882a593Smuzhiyun 	unsigned long tc_flower_cookie;
320*4882a593Smuzhiyun 	struct rhash_head fl_node;
321*4882a593Smuzhiyun 	struct rcu_head rcu;
322*4882a593Smuzhiyun 	__be32 nfp_tun_ipv4_addr;
323*4882a593Smuzhiyun 	struct nfp_ipv6_addr_entry *nfp_tun_ipv6;
324*4882a593Smuzhiyun 	struct net_device *ingress_dev;
325*4882a593Smuzhiyun 	char *unmasked_data;
326*4882a593Smuzhiyun 	char *mask_data;
327*4882a593Smuzhiyun 	char *action_data;
328*4882a593Smuzhiyun 	struct list_head linked_flows;
329*4882a593Smuzhiyun 	bool in_hw;
330*4882a593Smuzhiyun 	struct {
331*4882a593Smuzhiyun 		struct net_device *dev;
332*4882a593Smuzhiyun 		__be16 vlan_tci;
333*4882a593Smuzhiyun 		__be16 port_idx;
334*4882a593Smuzhiyun 	} pre_tun_rule;
335*4882a593Smuzhiyun };
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun struct nfp_fl_payload_link {
338*4882a593Smuzhiyun 	/* A link contains a pointer to a merge flow and an associated sub_flow.
339*4882a593Smuzhiyun 	 * Each merge flow will feature in 2 links to its underlying sub_flows.
340*4882a593Smuzhiyun 	 * A sub_flow will have at least 1 link to a merge flow or more if it
341*4882a593Smuzhiyun 	 * has been used to create multiple merge flows.
342*4882a593Smuzhiyun 	 *
343*4882a593Smuzhiyun 	 * For a merge flow, 'linked_flows' in its nfp_fl_payload struct lists
344*4882a593Smuzhiyun 	 * all links to sub_flows (sub_flow.flow) via merge.list.
345*4882a593Smuzhiyun 	 * For a sub_flow, 'linked_flows' gives all links to merge flows it has
346*4882a593Smuzhiyun 	 * formed (merge_flow.flow) via sub_flow.list.
347*4882a593Smuzhiyun 	 */
348*4882a593Smuzhiyun 	struct {
349*4882a593Smuzhiyun 		struct list_head list;
350*4882a593Smuzhiyun 		struct nfp_fl_payload *flow;
351*4882a593Smuzhiyun 	} merge_flow, sub_flow;
352*4882a593Smuzhiyun };
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun extern const struct rhashtable_params nfp_flower_table_params;
355*4882a593Smuzhiyun extern const struct rhashtable_params merge_table_params;
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun struct nfp_merge_info {
358*4882a593Smuzhiyun 	u64 parent_ctx;
359*4882a593Smuzhiyun 	struct rhash_head ht_node;
360*4882a593Smuzhiyun };
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun struct nfp_fl_stats_frame {
363*4882a593Smuzhiyun 	__be32 stats_con_id;
364*4882a593Smuzhiyun 	__be32 pkt_count;
365*4882a593Smuzhiyun 	__be64 byte_count;
366*4882a593Smuzhiyun 	__be64 stats_cookie;
367*4882a593Smuzhiyun };
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun static inline bool
nfp_flower_internal_port_can_offload(struct nfp_app * app,struct net_device * netdev)370*4882a593Smuzhiyun nfp_flower_internal_port_can_offload(struct nfp_app *app,
371*4882a593Smuzhiyun 				     struct net_device *netdev)
372*4882a593Smuzhiyun {
373*4882a593Smuzhiyun 	struct nfp_flower_priv *app_priv = app->priv;
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun 	if (!(app_priv->flower_en_feats & NFP_FL_ENABLE_FLOW_MERGE))
376*4882a593Smuzhiyun 		return false;
377*4882a593Smuzhiyun 	if (!netdev->rtnl_link_ops)
378*4882a593Smuzhiyun 		return false;
379*4882a593Smuzhiyun 	if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
380*4882a593Smuzhiyun 		return true;
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	return false;
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun /* The address of the merged flow acts as its cookie.
386*4882a593Smuzhiyun  * Cookies supplied to us by TC flower are also addresses to allocated
387*4882a593Smuzhiyun  * memory and thus this scheme should not generate any collisions.
388*4882a593Smuzhiyun  */
nfp_flower_is_merge_flow(struct nfp_fl_payload * flow_pay)389*4882a593Smuzhiyun static inline bool nfp_flower_is_merge_flow(struct nfp_fl_payload *flow_pay)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun 	return flow_pay->tc_flower_cookie == (unsigned long)flow_pay;
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun 
nfp_flower_is_supported_bridge(struct net_device * netdev)394*4882a593Smuzhiyun static inline bool nfp_flower_is_supported_bridge(struct net_device *netdev)
395*4882a593Smuzhiyun {
396*4882a593Smuzhiyun 	return netif_is_ovs_master(netdev);
397*4882a593Smuzhiyun }
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
400*4882a593Smuzhiyun 			     unsigned int host_ctx_split);
401*4882a593Smuzhiyun void nfp_flower_metadata_cleanup(struct nfp_app *app);
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
404*4882a593Smuzhiyun 			enum tc_setup_type type, void *type_data);
405*4882a593Smuzhiyun int nfp_flower_merge_offloaded_flows(struct nfp_app *app,
406*4882a593Smuzhiyun 				     struct nfp_fl_payload *sub_flow1,
407*4882a593Smuzhiyun 				     struct nfp_fl_payload *sub_flow2);
408*4882a593Smuzhiyun int nfp_flower_compile_flow_match(struct nfp_app *app,
409*4882a593Smuzhiyun 				  struct flow_cls_offload *flow,
410*4882a593Smuzhiyun 				  struct nfp_fl_key_ls *key_ls,
411*4882a593Smuzhiyun 				  struct net_device *netdev,
412*4882a593Smuzhiyun 				  struct nfp_fl_payload *nfp_flow,
413*4882a593Smuzhiyun 				  enum nfp_flower_tun_type tun_type,
414*4882a593Smuzhiyun 				  struct netlink_ext_ack *extack);
415*4882a593Smuzhiyun int nfp_flower_compile_action(struct nfp_app *app,
416*4882a593Smuzhiyun 			      struct flow_cls_offload *flow,
417*4882a593Smuzhiyun 			      struct net_device *netdev,
418*4882a593Smuzhiyun 			      struct nfp_fl_payload *nfp_flow,
419*4882a593Smuzhiyun 			      struct netlink_ext_ack *extack);
420*4882a593Smuzhiyun int nfp_compile_flow_metadata(struct nfp_app *app,
421*4882a593Smuzhiyun 			      struct flow_cls_offload *flow,
422*4882a593Smuzhiyun 			      struct nfp_fl_payload *nfp_flow,
423*4882a593Smuzhiyun 			      struct net_device *netdev,
424*4882a593Smuzhiyun 			      struct netlink_ext_ack *extack);
425*4882a593Smuzhiyun void __nfp_modify_flow_metadata(struct nfp_flower_priv *priv,
426*4882a593Smuzhiyun 				struct nfp_fl_payload *nfp_flow);
427*4882a593Smuzhiyun int nfp_modify_flow_metadata(struct nfp_app *app,
428*4882a593Smuzhiyun 			     struct nfp_fl_payload *nfp_flow);
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun struct nfp_fl_payload *
431*4882a593Smuzhiyun nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
432*4882a593Smuzhiyun 			   struct net_device *netdev);
433*4882a593Smuzhiyun struct nfp_fl_payload *
434*4882a593Smuzhiyun nfp_flower_get_fl_payload_from_ctx(struct nfp_app *app, u32 ctx_id);
435*4882a593Smuzhiyun struct nfp_fl_payload *
436*4882a593Smuzhiyun nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun int nfp_tunnel_config_start(struct nfp_app *app);
441*4882a593Smuzhiyun void nfp_tunnel_config_stop(struct nfp_app *app);
442*4882a593Smuzhiyun int nfp_tunnel_mac_event_handler(struct nfp_app *app,
443*4882a593Smuzhiyun 				 struct net_device *netdev,
444*4882a593Smuzhiyun 				 unsigned long event, void *ptr);
445*4882a593Smuzhiyun void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
446*4882a593Smuzhiyun void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
447*4882a593Smuzhiyun void
448*4882a593Smuzhiyun nfp_tunnel_put_ipv6_off(struct nfp_app *app, struct nfp_ipv6_addr_entry *entry);
449*4882a593Smuzhiyun struct nfp_ipv6_addr_entry *
450*4882a593Smuzhiyun nfp_tunnel_add_ipv6_off(struct nfp_app *app, struct in6_addr *ipv6);
451*4882a593Smuzhiyun void nfp_tunnel_request_route_v4(struct nfp_app *app, struct sk_buff *skb);
452*4882a593Smuzhiyun void nfp_tunnel_request_route_v6(struct nfp_app *app, struct sk_buff *skb);
453*4882a593Smuzhiyun void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
454*4882a593Smuzhiyun void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb);
455*4882a593Smuzhiyun void nfp_flower_lag_init(struct nfp_fl_lag *lag);
456*4882a593Smuzhiyun void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
457*4882a593Smuzhiyun int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
458*4882a593Smuzhiyun int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
459*4882a593Smuzhiyun 				struct net_device *netdev,
460*4882a593Smuzhiyun 				unsigned long event, void *ptr);
461*4882a593Smuzhiyun bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
462*4882a593Smuzhiyun int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
463*4882a593Smuzhiyun 				       struct net_device *master,
464*4882a593Smuzhiyun 				       struct nfp_fl_pre_lag *pre_act,
465*4882a593Smuzhiyun 				       struct netlink_ext_ack *extack);
466*4882a593Smuzhiyun int nfp_flower_lag_get_output_id(struct nfp_app *app,
467*4882a593Smuzhiyun 				 struct net_device *master);
468*4882a593Smuzhiyun void nfp_flower_qos_init(struct nfp_app *app);
469*4882a593Smuzhiyun void nfp_flower_qos_cleanup(struct nfp_app *app);
470*4882a593Smuzhiyun int nfp_flower_setup_qos_offload(struct nfp_app *app, struct net_device *netdev,
471*4882a593Smuzhiyun 				 struct tc_cls_matchall_offload *flow);
472*4882a593Smuzhiyun void nfp_flower_stats_rlim_reply(struct nfp_app *app, struct sk_buff *skb);
473*4882a593Smuzhiyun int nfp_flower_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, void *cb_priv,
474*4882a593Smuzhiyun 				enum tc_setup_type type, void *type_data,
475*4882a593Smuzhiyun 				void *data,
476*4882a593Smuzhiyun 				void (*cleanup)(struct flow_block_cb *block_cb));
477*4882a593Smuzhiyun void nfp_flower_setup_indr_tc_release(void *cb_priv);
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun void
480*4882a593Smuzhiyun __nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv);
481*4882a593Smuzhiyun struct nfp_flower_non_repr_priv *
482*4882a593Smuzhiyun nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev);
483*4882a593Smuzhiyun void
484*4882a593Smuzhiyun __nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv);
485*4882a593Smuzhiyun void
486*4882a593Smuzhiyun nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev);
487*4882a593Smuzhiyun u32 nfp_flower_get_port_id_from_netdev(struct nfp_app *app,
488*4882a593Smuzhiyun 				       struct net_device *netdev);
489*4882a593Smuzhiyun int nfp_flower_xmit_pre_tun_flow(struct nfp_app *app,
490*4882a593Smuzhiyun 				 struct nfp_fl_payload *flow);
491*4882a593Smuzhiyun int nfp_flower_xmit_pre_tun_del_flow(struct nfp_app *app,
492*4882a593Smuzhiyun 				     struct nfp_fl_payload *flow);
493*4882a593Smuzhiyun #endif
494