2 * This file is part of the Chelsio T4 Ethernet driver for Linux.
4 * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #ifndef __CXGB4_TC_U32_PARSE_H
36 #define __CXGB4_TC_U32_PARSE_H
38 struct cxgb4_match_field
{
39 int off
; /* Offset from the beginning of the header to match */
40 /* Fill the value/mask pair in the spec if matched */
41 int (*val
)(struct ch_filter_specification
*f
, u32 val
, u32 mask
);
44 /* IPv4 match fields */
45 static inline int cxgb4_fill_ipv4_tos(struct ch_filter_specification
*f
,
48 f
->val
.tos
= (ntohl(val
) >> 16) & 0x000000FF;
49 f
->mask
.tos
= (ntohl(mask
) >> 16) & 0x000000FF;
54 static inline int cxgb4_fill_ipv4_frag(struct ch_filter_specification
*f
,
60 frag_val
= (ntohl(val
) >> 13) & 0x00000007;
61 mask_val
= ntohl(mask
) & 0x0000FFFF;
63 if (frag_val
== 0x1 && mask_val
!= 0x3FFF) { /* MF set */
66 } else if (frag_val
== 0x2 && mask_val
!= 0x3FFF) { /* DF set */
76 static inline int cxgb4_fill_ipv4_proto(struct ch_filter_specification
*f
,
79 f
->val
.proto
= (ntohl(val
) >> 16) & 0x000000FF;
80 f
->mask
.proto
= (ntohl(mask
) >> 16) & 0x000000FF;
85 static inline int cxgb4_fill_ipv4_src_ip(struct ch_filter_specification
*f
,
88 memcpy(&f
->val
.fip
[0], &val
, sizeof(u32
));
89 memcpy(&f
->mask
.fip
[0], &mask
, sizeof(u32
));
94 static inline int cxgb4_fill_ipv4_dst_ip(struct ch_filter_specification
*f
,
97 memcpy(&f
->val
.lip
[0], &val
, sizeof(u32
));
98 memcpy(&f
->mask
.lip
[0], &mask
, sizeof(u32
));
103 static const struct cxgb4_match_field cxgb4_ipv4_fields
[] = {
104 { .off
= 0, .val
= cxgb4_fill_ipv4_tos
},
105 { .off
= 4, .val
= cxgb4_fill_ipv4_frag
},
106 { .off
= 8, .val
= cxgb4_fill_ipv4_proto
},
107 { .off
= 12, .val
= cxgb4_fill_ipv4_src_ip
},
108 { .off
= 16, .val
= cxgb4_fill_ipv4_dst_ip
},
112 /* IPv6 match fields */
113 static inline int cxgb4_fill_ipv6_tos(struct ch_filter_specification
*f
,
116 f
->val
.tos
= (ntohl(val
) >> 20) & 0x000000FF;
117 f
->mask
.tos
= (ntohl(mask
) >> 20) & 0x000000FF;
122 static inline int cxgb4_fill_ipv6_proto(struct ch_filter_specification
*f
,
125 f
->val
.proto
= (ntohl(val
) >> 8) & 0x000000FF;
126 f
->mask
.proto
= (ntohl(mask
) >> 8) & 0x000000FF;
131 static inline int cxgb4_fill_ipv6_src_ip0(struct ch_filter_specification
*f
,
134 memcpy(&f
->val
.fip
[0], &val
, sizeof(u32
));
135 memcpy(&f
->mask
.fip
[0], &mask
, sizeof(u32
));
140 static inline int cxgb4_fill_ipv6_src_ip1(struct ch_filter_specification
*f
,
143 memcpy(&f
->val
.fip
[4], &val
, sizeof(u32
));
144 memcpy(&f
->mask
.fip
[4], &mask
, sizeof(u32
));
149 static inline int cxgb4_fill_ipv6_src_ip2(struct ch_filter_specification
*f
,
152 memcpy(&f
->val
.fip
[8], &val
, sizeof(u32
));
153 memcpy(&f
->mask
.fip
[8], &mask
, sizeof(u32
));
158 static inline int cxgb4_fill_ipv6_src_ip3(struct ch_filter_specification
*f
,
161 memcpy(&f
->val
.fip
[12], &val
, sizeof(u32
));
162 memcpy(&f
->mask
.fip
[12], &mask
, sizeof(u32
));
167 static inline int cxgb4_fill_ipv6_dst_ip0(struct ch_filter_specification
*f
,
170 memcpy(&f
->val
.lip
[0], &val
, sizeof(u32
));
171 memcpy(&f
->mask
.lip
[0], &mask
, sizeof(u32
));
176 static inline int cxgb4_fill_ipv6_dst_ip1(struct ch_filter_specification
*f
,
179 memcpy(&f
->val
.lip
[4], &val
, sizeof(u32
));
180 memcpy(&f
->mask
.lip
[4], &mask
, sizeof(u32
));
185 static inline int cxgb4_fill_ipv6_dst_ip2(struct ch_filter_specification
*f
,
188 memcpy(&f
->val
.lip
[8], &val
, sizeof(u32
));
189 memcpy(&f
->mask
.lip
[8], &mask
, sizeof(u32
));
194 static inline int cxgb4_fill_ipv6_dst_ip3(struct ch_filter_specification
*f
,
197 memcpy(&f
->val
.lip
[12], &val
, sizeof(u32
));
198 memcpy(&f
->mask
.lip
[12], &mask
, sizeof(u32
));
203 static const struct cxgb4_match_field cxgb4_ipv6_fields
[] = {
204 { .off
= 0, .val
= cxgb4_fill_ipv6_tos
},
205 { .off
= 4, .val
= cxgb4_fill_ipv6_proto
},
206 { .off
= 8, .val
= cxgb4_fill_ipv6_src_ip0
},
207 { .off
= 12, .val
= cxgb4_fill_ipv6_src_ip1
},
208 { .off
= 16, .val
= cxgb4_fill_ipv6_src_ip2
},
209 { .off
= 20, .val
= cxgb4_fill_ipv6_src_ip3
},
210 { .off
= 24, .val
= cxgb4_fill_ipv6_dst_ip0
},
211 { .off
= 28, .val
= cxgb4_fill_ipv6_dst_ip1
},
212 { .off
= 32, .val
= cxgb4_fill_ipv6_dst_ip2
},
213 { .off
= 36, .val
= cxgb4_fill_ipv6_dst_ip3
},
218 static inline int cxgb4_fill_l4_ports(struct ch_filter_specification
*f
,
221 f
->val
.fport
= ntohl(val
) >> 16;
222 f
->mask
.fport
= ntohl(mask
) >> 16;
223 f
->val
.lport
= ntohl(val
) & 0x0000FFFF;
224 f
->mask
.lport
= ntohl(mask
) & 0x0000FFFF;
229 static const struct cxgb4_match_field cxgb4_tcp_fields
[] = {
230 { .off
= 0, .val
= cxgb4_fill_l4_ports
},
234 static const struct cxgb4_match_field cxgb4_udp_fields
[] = {
235 { .off
= 0, .val
= cxgb4_fill_l4_ports
},
239 struct cxgb4_next_header
{
240 unsigned int offset
; /* Offset to next header */
241 /* offset, shift, and mask added to offset above
242 * to get to next header. Useful when using a header
243 * field's value to jump to next header such as IHL field
249 /* match criteria to make this jump */
250 unsigned int match_off
;
253 /* location of jump to make */
254 const struct cxgb4_match_field
*jump
;
257 /* Accept a rule with a jump to transport layer header based on IHL field in
260 static const struct cxgb4_next_header cxgb4_ipv4_jumps
[] = {
261 { .offset
= 0, .offoff
= 0, .shift
= 6, .mask
= 0xF,
262 .match_off
= 8, .match_val
= 0x600, .match_mask
= 0xFF00,
263 .jump
= cxgb4_tcp_fields
},
264 { .offset
= 0, .offoff
= 0, .shift
= 6, .mask
= 0xF,
265 .match_off
= 8, .match_val
= 0x1100, .match_mask
= 0xFF00,
266 .jump
= cxgb4_udp_fields
},
270 /* Accept a rule with a jump directly past the 40 Bytes of IPv6 fixed header
271 * to get to transport layer header.
273 static const struct cxgb4_next_header cxgb4_ipv6_jumps
[] = {
274 { .offset
= 0x28, .offoff
= 0, .shift
= 0, .mask
= 0,
275 .match_off
= 4, .match_val
= 0x60000, .match_mask
= 0xFF0000,
276 .jump
= cxgb4_tcp_fields
},
277 { .offset
= 0x28, .offoff
= 0, .shift
= 0, .mask
= 0,
278 .match_off
= 4, .match_val
= 0x110000, .match_mask
= 0xFF0000,
279 .jump
= cxgb4_udp_fields
},
284 const struct cxgb4_match_field
*match_field
; /* Next header */
285 struct ch_filter_specification fs
; /* Match spec associated with link */
286 u32 link_handle
; /* Knode handle associated with the link */
287 unsigned long *tid_map
; /* Bitmap for filter tids */
290 struct cxgb4_tc_u32_table
{
291 unsigned int size
; /* number of entries in table */
292 struct cxgb4_link table
[0]; /* Jump table */
294 #endif /* __CXGB4_TC_U32_PARSE_H */