1
2
3
4
5
6#ifndef _CXGBE_FILTER_H_
7#define _CXGBE_FILTER_H_
8
9#include "base/t4_msg.h"
10
11
12
13#define ETHTYPE_BITWIDTH 16
14#define FRAG_BITWIDTH 1
15#define MACIDX_BITWIDTH 9
16#define FCOE_BITWIDTH 1
17#define IPORT_BITWIDTH 3
18#define MATCHTYPE_BITWIDTH 3
19#define PROTO_BITWIDTH 8
20#define TOS_BITWIDTH 8
21#define PF_BITWIDTH 3
22#define VF_BITWIDTH 13
23#define IVLAN_BITWIDTH 16
24#define OVLAN_BITWIDTH 16
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39struct ch_filter_tuple {
40
41
42
43
44
45
46
47 uint32_t ethtype:ETHTYPE_BITWIDTH;
48 uint32_t frag:FRAG_BITWIDTH;
49 uint32_t ivlan_vld:1;
50 uint32_t ovlan_vld:1;
51 uint32_t pfvf_vld:1;
52 uint32_t macidx:MACIDX_BITWIDTH;
53 uint32_t fcoe:FCOE_BITWIDTH;
54 uint32_t iport:IPORT_BITWIDTH;
55 uint32_t matchtype:MATCHTYPE_BITWIDTH;
56 uint32_t proto:PROTO_BITWIDTH;
57 uint32_t tos:TOS_BITWIDTH;
58 uint32_t pf:PF_BITWIDTH;
59 uint32_t vf:VF_BITWIDTH;
60 uint32_t ivlan:IVLAN_BITWIDTH;
61 uint32_t ovlan:OVLAN_BITWIDTH;
62
63
64
65
66
67 uint8_t lip[16];
68 uint8_t fip[16];
69 uint16_t lport;
70 uint16_t fport;
71
72 uint8_t dmac[6];
73
74
75 uint8_t rsvd[6];
76};
77
78
79
80
81struct ch_filter_specification {
82 void *private;
83
84 uint32_t hitcnts:1;
85 uint32_t prio:1;
86
87
88
89
90
91 uint32_t type:1;
92 uint32_t cap:1;
93
94
95
96
97
98
99 uint32_t action:2;
100
101 uint32_t dirsteer:1;
102 uint32_t iq:10;
103
104 uint32_t eport:2;
105 uint32_t newsmac:1;
106 uint32_t newdmac:1;
107 uint32_t swapmac:1;
108 uint32_t newvlan:2;
109 uint8_t smac[RTE_ETHER_ADDR_LEN];
110 uint8_t dmac[RTE_ETHER_ADDR_LEN];
111 uint16_t vlan;
112
113
114
115
116
117
118 uint32_t nat_mode:3;
119
120 uint8_t nat_lip[16];
121 uint8_t nat_fip[16];
122 uint16_t nat_lport;
123 uint16_t nat_fport;
124
125
126 struct ch_filter_tuple val;
127 struct ch_filter_tuple mask;
128};
129
130enum {
131 FILTER_PASS = 0,
132 FILTER_DROP,
133 FILTER_SWITCH
134};
135
136enum {
137 VLAN_REMOVE = 1,
138 VLAN_INSERT,
139 VLAN_REWRITE
140};
141
142enum {
143 NAT_MODE_NONE = 0,
144 NAT_MODE_DIP,
145 NAT_MODE_DIP_DP,
146 NAT_MODE_DIP_DP_SIP,
147 NAT_MODE_DIP_DP_SP,
148 NAT_MODE_SIP_SP,
149 NAT_MODE_DIP_SIP_SP,
150 NAT_MODE_ALL
151};
152
153enum filter_type {
154 FILTER_TYPE_IPV4 = 0,
155 FILTER_TYPE_IPV6,
156};
157
158struct t4_completion {
159 unsigned int done;
160 rte_spinlock_t lock;
161};
162
163
164
165
166
167struct filter_ctx {
168 struct t4_completion completion;
169 int result;
170 u32 tid;
171};
172
173
174
175
176
177
178struct filter_entry {
179
180
181
182 u32 valid:1;
183 u32 locked:1;
184 u32 pending:1;
185 struct filter_ctx *ctx;
186 struct clip_entry *clipt;
187 struct l2t_entry *l2t;
188 struct smt_entry *smt;
189 struct rte_eth_dev *dev;
190 void *private;
191
192
193 u32 tid;
194
195
196
197
198 struct ch_filter_specification fs;
199};
200
201#define FILTER_ID_MAX (~0U)
202
203struct tid_info;
204struct adapter;
205
206
207
208
209static inline unsigned int cxgbe_find_first_zero_bit(struct rte_bitmap *bmap,
210 unsigned int size)
211{
212 unsigned int idx;
213
214 for (idx = 0; idx < size; idx++)
215 if (!rte_bitmap_get(bmap, idx))
216 break;
217
218 return idx;
219}
220
221
222
223
224static inline unsigned int
225cxgbe_bitmap_find_free_region(struct rte_bitmap *bmap, unsigned int size,
226 unsigned int num)
227{
228 unsigned int idx, j, free = 0;
229
230 if (num > size)
231 return size;
232
233 for (idx = 0; idx < size; idx += num) {
234 for (j = 0; j < num; j++) {
235 if (!rte_bitmap_get(bmap, idx + j)) {
236 free++;
237 } else {
238 free = 0;
239 break;
240 }
241 }
242
243
244 if (free == num)
245 break;
246
247
248 if ((idx + num) > size) {
249 idx = size;
250 break;
251 }
252 }
253
254 return idx;
255}
256
257u8 cxgbe_filter_slots(struct adapter *adap, u8 family);
258bool cxgbe_is_filter_set(struct tid_info *t, u32 fidx, u8 nentries);
259void cxgbe_filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl);
260int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
261 struct ch_filter_specification *fs,
262 struct filter_ctx *ctx);
263int cxgbe_del_filter(struct rte_eth_dev *dev, unsigned int filter_id,
264 struct ch_filter_specification *fs,
265 struct filter_ctx *ctx);
266int cxgbe_alloc_ftid(struct adapter *adap, u8 nentries);
267int cxgbe_init_hash_filter(struct adapter *adap);
268void cxgbe_hash_filter_rpl(struct adapter *adap,
269 const struct cpl_act_open_rpl *rpl);
270void cxgbe_hash_del_filter_rpl(struct adapter *adap,
271 const struct cpl_abort_rpl_rss *rpl);
272int cxgbe_validate_filter(struct adapter *adap,
273 struct ch_filter_specification *fs);
274int cxgbe_get_filter_count(struct adapter *adapter, unsigned int fidx,
275 u64 *c, int hash, bool get_byte);
276int cxgbe_clear_filter_count(struct adapter *adapter, unsigned int fidx,
277 int hash, bool clear_byte);
278#endif
279