net/ice/base: add non-word aligned IPv4 field support
[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_IPV4_TOS_OFFSET             15
86 #define ICE_IPV4_TTL_OFFSET             22
87
88 #define ICE_FDIR_MAX_FLTRS              16384
89
90 /* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF
91  * requests that the packet not be fragmented. MF indicates that a packet has
92  * been fragmented.
93  */
94 #define ICE_FDIR_IPV4_PKT_FLAG_DF               0x20
95 #define ICE_FDIR_IPV4_PKT_FLAG_MF               0x40
96
97 enum ice_fltr_prgm_desc_dest {
98         ICE_FLTR_PRGM_DESC_DEST_DROP_PKT,
99         ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX,
100         ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP,
101         ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER,
102 };
103
104 enum ice_fltr_prgm_desc_fd_status {
105         ICE_FLTR_PRGM_DESC_FD_STATUS_NONE,
106         ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID,
107         ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID_4FLEX_BYTES,
108         ICE_FLTR_PRGM_DESC_FD_STATUS_8FLEX_BYTES,
109 };
110
111 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE    sizeof(__be16)
112
113 struct ice_rx_flow_userdef {
114         u16 flex_word;
115         u16 flex_offset;
116         u16 flex_fltr;
117 };
118
119 struct ice_fdir_v4 {
120         __be32 dst_ip;
121         __be32 src_ip;
122         __be16 dst_port;
123         __be16 src_port;
124         __be32 l4_header;
125         __be32 sec_parm_idx;    /* security parameter index */
126         u8 tos;
127         u8 ip_ver;
128         u8 proto;
129         u8 ttl;
130 };
131
132 #define ICE_IPV6_ADDR_LEN_AS_U32                4
133
134 struct ice_fdir_v6 {
135         __be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32];
136         __be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32];
137         __be16 dst_port;
138         __be16 src_port;
139         __be32 l4_header; /* next header */
140         __be32 sec_parm_idx; /* security parameter index */
141         u8 tc;
142         u8 proto;
143 };
144
145 struct ice_fdir_extra {
146         u8 dst_mac[ETH_ALEN];   /* dest MAC address */
147         u32 usr_def[2];         /* user data */
148         __be16 vlan_type;       /* VLAN ethertype */
149         __be16 vlan_tag;        /* VLAN tag info */
150 };
151
152 struct ice_fdir_fltr {
153         struct LIST_ENTRY_TYPE fltr_node;
154         enum ice_fltr_ptype flow_type;
155
156         union {
157                 struct ice_fdir_v4 v4;
158                 struct ice_fdir_v6 v6;
159         } ip, mask;
160
161         struct ice_fdir_extra ext_data;
162         struct ice_fdir_extra ext_mask;
163
164         /* flex byte filter data */
165         __be16 flex_word;
166         u16 flex_offset;
167         u16 flex_fltr;
168
169         /* filter control */
170         u16 q_index;
171         u16 dest_vsi;
172         u8 dest_ctl;
173         u8 fltr_status;
174         u16 cnt_index;
175         u32 fltr_id;
176 };
177
178 /* Dummy packet filter definition structure. */
179 struct ice_fdir_base_pkt {
180         enum ice_fltr_ptype flow;
181         u16 pkt_len;
182         const u8 *pkt;
183         u16 tun_pkt_len;
184         const u8 *tun_pkt;
185 };
186
187 void
188 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
189                        struct ice_fltr_desc *fdesc, bool add);
190 enum ice_status
191 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
192                           u8 *pkt, bool frag, bool tun);
193 enum ice_status
194 ice_fdir_get_prgm_pkt(struct ice_fdir_fltr *input, u8 *pkt, bool frag);
195 enum ice_status
196 ice_add_del_fdir(struct ice_hw *hw, struct ice_fdir_fltr *input, bool add);
197 int ice_get_fdir_cnt_all(struct ice_hw *hw);
198 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
199 enum ice_status
200 ice_update_fdir_list_entry(struct ice_hw *hw, struct ice_fdir_fltr *input,
201                            u16 sw_idx);
202 bool ice_fdir_has_frag(enum ice_fltr_ptype flow);
203 struct ice_fdir_fltr *
204 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx);
205 void
206 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add);
207 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
208 #endif /* _ICE_FDIR_H_ */