xref: /openbmc/linux/drivers/net/ethernet/intel/iavf/iavf_fdir.h (revision 8b0adbe3e38dbe5aae9edf6f5159ffdca7cfbdf1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2021, Intel Corporation. */
3 
4 #ifndef _IAVF_FDIR_H_
5 #define _IAVF_FDIR_H_
6 
7 struct iavf_adapter;
8 
9 /* State of Flow Director filter */
10 enum iavf_fdir_fltr_state_t {
11 	IAVF_FDIR_FLTR_ADD_REQUEST,	/* User requests to add filter */
12 	IAVF_FDIR_FLTR_ADD_PENDING,	/* Filter pending add by the PF */
13 	IAVF_FDIR_FLTR_DEL_REQUEST,	/* User requests to delete filter */
14 	IAVF_FDIR_FLTR_DEL_PENDING,	/* Filter pending delete by the PF */
15 	IAVF_FDIR_FLTR_ACTIVE,		/* Filter is active */
16 };
17 
18 enum iavf_fdir_flow_type {
19 	/* NONE - used for undef/error */
20 	IAVF_FDIR_FLOW_NONE = 0,
21 	IAVF_FDIR_FLOW_IPV4_TCP,
22 	IAVF_FDIR_FLOW_IPV4_UDP,
23 	IAVF_FDIR_FLOW_IPV4_SCTP,
24 	IAVF_FDIR_FLOW_IPV4_AH,
25 	IAVF_FDIR_FLOW_IPV4_ESP,
26 	IAVF_FDIR_FLOW_IPV4_OTHER,
27 	IAVF_FDIR_FLOW_IPV6_TCP,
28 	IAVF_FDIR_FLOW_IPV6_UDP,
29 	IAVF_FDIR_FLOW_IPV6_SCTP,
30 	IAVF_FDIR_FLOW_IPV6_AH,
31 	IAVF_FDIR_FLOW_IPV6_ESP,
32 	IAVF_FDIR_FLOW_IPV6_OTHER,
33 	IAVF_FDIR_FLOW_NON_IP_L2,
34 	/* MAX - this must be last and add anything new just above it */
35 	IAVF_FDIR_FLOW_PTYPE_MAX,
36 };
37 
38 struct iavf_flex_word {
39 	u16 offset;
40 	u16 word;
41 };
42 
43 struct iavf_ipv4_addrs {
44 	__be32 src_ip;
45 	__be32 dst_ip;
46 };
47 
48 struct iavf_ipv6_addrs {
49 	struct in6_addr src_ip;
50 	struct in6_addr dst_ip;
51 };
52 
53 struct iavf_fdir_eth {
54 	__be16 etype;
55 };
56 
57 struct iavf_fdir_ip {
58 	union {
59 		struct iavf_ipv4_addrs v4_addrs;
60 		struct iavf_ipv6_addrs v6_addrs;
61 	};
62 	__be16 src_port;
63 	__be16 dst_port;
64 	__be32 l4_header;	/* first 4 bytes of the layer 4 header */
65 	__be32 spi;		/* security parameter index for AH/ESP */
66 	union {
67 		u8 tos;
68 		u8 tclass;
69 	};
70 	u8 proto;
71 };
72 
73 struct iavf_fdir_extra {
74 	u32 usr_def[2];
75 };
76 
77 /* bookkeeping of Flow Director filters */
78 struct iavf_fdir_fltr {
79 	enum iavf_fdir_fltr_state_t state;
80 	struct list_head list;
81 
82 	enum iavf_fdir_flow_type flow_type;
83 
84 	struct iavf_fdir_eth eth_data;
85 	struct iavf_fdir_eth eth_mask;
86 
87 	struct iavf_fdir_ip ip_data;
88 	struct iavf_fdir_ip ip_mask;
89 
90 	struct iavf_fdir_extra ext_data;
91 	struct iavf_fdir_extra ext_mask;
92 
93 	enum virtchnl_action action;
94 
95 	/* flex byte filter data */
96 	u8 ip_ver; /* used to adjust the flex offset, 4 : IPv4, 6 : IPv6 */
97 	u8 flex_cnt;
98 	struct iavf_flex_word flex_words[2];
99 
100 	u32 flow_id;
101 
102 	u32 loc;	/* Rule location inside the flow table */
103 	u32 q_index;
104 
105 	struct virtchnl_fdir_add vc_add_msg;
106 };
107 
108 int iavf_fill_fdir_add_msg(struct iavf_adapter *adapter, struct iavf_fdir_fltr *fltr);
109 void iavf_print_fdir_fltr(struct iavf_adapter *adapter, struct iavf_fdir_fltr *fltr);
110 bool iavf_fdir_is_dup_fltr(struct iavf_adapter *adapter, struct iavf_fdir_fltr *fltr);
111 void iavf_fdir_list_add_fltr(struct iavf_adapter *adapter, struct iavf_fdir_fltr *fltr);
112 struct iavf_fdir_fltr *iavf_find_fdir_fltr_by_loc(struct iavf_adapter *adapter, u32 loc);
113 #endif /* _IAVF_FDIR_H_ */
114