net/ice/base: support tunnel packets
[dpdk.git] / drivers / net / ice / base / ice_fdir.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2019
3  */
4
5 #ifndef _ICE_FDIR_H_
6 #define _ICE_FDIR_H_
7
8 #include "ice_common.h"
9
10 /* Flow Director (FD) Filter Programming descriptor */
11 struct ice_fd_fltr_desc_ctx {
12         u32 fdid;
13         u16 qindex;
14         u16 cnt_index;
15         u16 fd_vsi;
16         u16 flex_val;
17         u8 comp_q;
18         u8 comp_report;
19         u8 fd_space;
20         u8 cnt_ena;
21         u8 evict_ena;
22         u8 toq;
23         u8 toq_prio;
24         u8 dpu_recipe;
25         u8 drop;
26         u8 flex_prio;
27         u8 flex_mdid;
28         u8 dtype;
29         u8 pcmd;
30         u8 desc_prof_prio;
31         u8 desc_prof;
32         u8 swap;
33         u8 fdid_prio;
34         u8 fdid_mdid;
35 };
36
37 enum ice_status ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id);
38 enum ice_status ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id);
39 void
40 ice_set_fd_desc_val(struct ice_fd_fltr_desc_ctx *fd_fltr_ctx,
41                     struct ice_fltr_desc *fdir_desc);
42 void ice_set_dflt_val_fd_desc(struct ice_fd_fltr_desc_ctx *fd_fltr_ctx);
43 enum ice_status
44 ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
45 enum ice_status
46 ice_free_fd_guar_item(struct ice_hw *hw, u16 cntr_id, u16 num_fltr);
47 enum ice_status
48 ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
49 enum ice_status
50 ice_free_fd_shrd_item(struct ice_hw *hw, u16 cntr_id, u16 num_fltr);
51 enum ice_status ice_clear_vsi_fd_table(struct ice_hw *hw, u16 vsi_num);
52 enum ice_status ice_clear_pf_fd_table(struct ice_hw *hw);
53
54 #define ICE_FDIR_IP_PROTOCOLS
55 #define ICE_IP_PROTO_TCP                6
56 #define ICE_IP_PROTO_UDP                17
57 #define ICE_IP_PROTO_SCTP               132
58 #define ICE_IP_PROTO_IP                 0
59 #define ICE_IP_PROTO_ESP                50
60
61 #define ICE_FDIR_TUN_PKT_OFF            50
62 #define ICE_FDIR_MAX_RAW_PKT_SIZE       (512 + ICE_FDIR_TUN_PKT_OFF)
63 #define ICE_FDIR_BUF_FULL_MARGIN        10
64 #define ICE_FDIR_BUF_HEAD_ROOM          32
65
66 /* macros for offsets into packets for flow director programming */
67 #define ICE_IPV4_SRC_ADDR_OFFSET        26
68 #define ICE_IPV4_DST_ADDR_OFFSET        30
69 #define ICE_IPV4_TCP_SRC_PORT_OFFSET    34
70 #define ICE_IPV4_TCP_DST_PORT_OFFSET    36
71 #define ICE_IPV4_UDP_SRC_PORT_OFFSET    34
72 #define ICE_IPV4_UDP_DST_PORT_OFFSET    36
73 #define ICE_IPV4_SCTP_SRC_PORT_OFFSET   34
74 #define ICE_IPV4_SCTP_DST_PORT_OFFSET   36
75 #define ICE_IPV4_PROTO_OFFSET           23
76 #define ICE_IPV6_SRC_ADDR_OFFSET        22
77 #define ICE_IPV6_DST_ADDR_OFFSET        38
78 #define ICE_IPV6_TCP_SRC_PORT_OFFSET    54
79 #define ICE_IPV6_TCP_DST_PORT_OFFSET    56
80 #define ICE_IPV6_UDP_SRC_PORT_OFFSET    54
81 #define ICE_IPV6_UDP_DST_PORT_OFFSET    56
82 #define ICE_IPV6_SCTP_SRC_PORT_OFFSET   54
83 #define ICE_IPV6_SCTP_DST_PORT_OFFSET   56
84
85 #define ICE_FDIR_MAX_FLTRS              16384
86
87 /* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF
88  * requests that the packet not be fragmented. MF indicates that a packet has
89  * been fragmented.
90  */
91 #define ICE_FDIR_IPV4_PKT_FLAG_DF               0x20
92 #define ICE_FDIR_IPV4_PKT_FLAG_MF               0x40
93
94 enum ice_fltr_prgm_desc_dest {
95         ICE_FLTR_PRGM_DESC_DEST_DROP_PKT,
96         ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX,
97         ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP,
98         ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER,
99 };
100
101 enum ice_fltr_prgm_desc_fd_status {
102         ICE_FLTR_PRGM_DESC_FD_STATUS_NONE,
103         ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID,
104         ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID_4FLEX_BYTES,
105         ICE_FLTR_PRGM_DESC_FD_STATUS_8FLEX_BYTES,
106 };
107
108 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE    sizeof(__be16)
109
110 struct ice_rx_flow_userdef {
111         u16 flex_word;
112         u16 flex_offset;
113         u16 flex_fltr;
114 };
115
116 struct ice_fdir_v4 {
117         __be32 dst_ip;
118         __be32 src_ip;
119         __be16 dst_port;
120         __be16 src_port;
121         __be32 l4_header;
122         __be32 sec_parm_idx;    /* security parameter index */
123         u8 tos;
124         u8 ip_ver;
125         u8 proto;
126 };
127
128 #define ICE_IPV6_ADDR_LEN_AS_U32                4
129
130 struct ice_fdir_v6 {
131         __be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32];
132         __be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32];
133         __be16 dst_port;
134         __be16 src_port;
135         __be32 l4_header; /* next header */
136         __be32 sec_parm_idx; /* security parameter index */
137         u8 tc;
138         u8 proto;
139 };
140
141 struct ice_fdir_extra {
142         u8 dst_mac[ETH_ALEN];   /* dest MAC address */
143         u32 usr_def[2];         /* user data */
144         __be16 vlan_type;       /* VLAN ethertype */
145         __be16 vlan_tag;        /* VLAN tag info */
146 };
147
148 struct ice_fdir_fltr {
149         struct LIST_ENTRY_TYPE fltr_node;
150         enum ice_fltr_ptype flow_type;
151
152         union {
153                 struct ice_fdir_v4 v4;
154                 struct ice_fdir_v6 v6;
155         } ip, mask;
156
157         struct ice_fdir_extra ext_data;
158         struct ice_fdir_extra ext_mask;
159
160         /* flex byte filter data */
161         __be16 flex_word;
162         u16 flex_offset;
163         u16 flex_fltr;
164
165         /* filter control */
166         u16 q_index;
167         u16 dest_vsi;
168         u8 dest_ctl;
169         u8 fltr_status;
170         u16 cnt_index;
171         u32 fltr_id;
172 };
173
174 /* Dummy packet filter definition structure. */
175 struct ice_fdir_base_pkt {
176         enum ice_fltr_ptype flow;
177         u16 pkt_len;
178         const u8 *pkt;
179         u16 tun_pkt_len;
180         const u8 *tun_pkt;
181 };
182
183 void
184 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
185                        struct ice_fltr_desc *fdesc, bool add);
186 enum ice_status
187 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
188                           u8 *pkt, bool frag, bool tun);
189 enum ice_status
190 ice_fdir_get_prgm_pkt(struct ice_fdir_fltr *input, u8 *pkt, bool frag);
191 enum ice_status
192 ice_add_del_fdir(struct ice_hw *hw, struct ice_fdir_fltr *input, bool add);
193 int ice_get_fdir_cnt_all(struct ice_hw *hw);
194 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
195 enum ice_status
196 ice_update_fdir_list_entry(struct ice_hw *hw, struct ice_fdir_fltr *input,
197                            u16 sw_idx);
198 bool ice_fdir_has_frag(enum ice_fltr_ptype flow);
199 struct ice_fdir_fltr *
200 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx);
201 void
202 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add);
203 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
204 #endif /* _ICE_FDIR_H_ */