]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/sfc/filter.h
Merge tag 'upstream-3.12-rc1' of git://git.infradead.org/linux-ubi
[karo-tx-linux.git] / drivers / net / ethernet / sfc / filter.h
1 /****************************************************************************
2  * Driver for Solarflare network controllers and boards
3  * Copyright 2005-2013 Solarflare Communications Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, incorporated herein by reference.
8  */
9
10 #ifndef EFX_FILTER_H
11 #define EFX_FILTER_H
12
13 #include <linux/types.h>
14 #include <linux/if_ether.h>
15 #include <asm/byteorder.h>
16
17 /**
18  * enum efx_filter_match_flags - Flags for hardware filter match type
19  * @EFX_FILTER_MATCH_REM_HOST: Match by remote IP host address
20  * @EFX_FILTER_MATCH_LOC_HOST: Match by local IP host address
21  * @EFX_FILTER_MATCH_REM_MAC: Match by remote MAC address
22  * @EFX_FILTER_MATCH_REM_PORT: Match by remote TCP/UDP port
23  * @EFX_FILTER_MATCH_LOC_MAC: Match by local MAC address
24  * @EFX_FILTER_MATCH_LOC_PORT: Match by local TCP/UDP port
25  * @EFX_FILTER_MATCH_ETHER_TYPE: Match by Ether-type
26  * @EFX_FILTER_MATCH_INNER_VID: Match by inner VLAN ID
27  * @EFX_FILTER_MATCH_OUTER_VID: Match by outer VLAN ID
28  * @EFX_FILTER_MATCH_IP_PROTO: Match by IP transport protocol
29  * @EFX_FILTER_MATCH_LOC_MAC_IG: Match by local MAC address I/G bit.
30  *      Used for RX default unicast and multicast/broadcast filters.
31  *
32  * Only some combinations are supported, depending on NIC type:
33  *
34  * - Falcon supports RX filters matching by {TCP,UDP}/IPv4 4-tuple or
35  *   local 2-tuple (only implemented for Falcon B0)
36  *
37  * - Siena supports RX and TX filters matching by {TCP,UDP}/IPv4 4-tuple
38  *   or local 2-tuple, or local MAC with or without outer VID, and RX
39  *   default filters
40  *
41  * - Huntington supports filter matching controlled by firmware, potentially
42  *   using {TCP,UDP}/IPv{4,6} 4-tuple or local 2-tuple, local MAC or I/G bit,
43  *   with or without outer and inner VID
44  */
45 enum efx_filter_match_flags {
46         EFX_FILTER_MATCH_REM_HOST =     0x0001,
47         EFX_FILTER_MATCH_LOC_HOST =     0x0002,
48         EFX_FILTER_MATCH_REM_MAC =      0x0004,
49         EFX_FILTER_MATCH_REM_PORT =     0x0008,
50         EFX_FILTER_MATCH_LOC_MAC =      0x0010,
51         EFX_FILTER_MATCH_LOC_PORT =     0x0020,
52         EFX_FILTER_MATCH_ETHER_TYPE =   0x0040,
53         EFX_FILTER_MATCH_INNER_VID =    0x0080,
54         EFX_FILTER_MATCH_OUTER_VID =    0x0100,
55         EFX_FILTER_MATCH_IP_PROTO =     0x0200,
56         EFX_FILTER_MATCH_LOC_MAC_IG =   0x0400,
57 };
58
59 /**
60  * enum efx_filter_priority - priority of a hardware filter specification
61  * @EFX_FILTER_PRI_HINT: Performance hint
62  * @EFX_FILTER_PRI_MANUAL: Manually configured filter
63  * @EFX_FILTER_PRI_REQUIRED: Required for correct behaviour (user-level
64  *      networking and SR-IOV)
65  */
66 enum efx_filter_priority {
67         EFX_FILTER_PRI_HINT = 0,
68         EFX_FILTER_PRI_MANUAL,
69         EFX_FILTER_PRI_REQUIRED,
70 };
71
72 /**
73  * enum efx_filter_flags - flags for hardware filter specifications
74  * @EFX_FILTER_FLAG_RX_RSS: Use RSS to spread across multiple queues.
75  *      By default, matching packets will be delivered only to the
76  *      specified queue. If this flag is set, they will be delivered
77  *      to a range of queues offset from the specified queue number
78  *      according to the indirection table.
79  * @EFX_FILTER_FLAG_RX_SCATTER: Enable DMA scatter on the receiving
80  *      queue.
81  * @EFX_FILTER_FLAG_RX_STACK: Indicates a filter inserted for the
82  *      network stack.  The filter must have a priority of
83  *      %EFX_FILTER_PRI_REQUIRED.  It can be steered by a replacement
84  *      request with priority %EFX_FILTER_PRI_MANUAL, and a removal
85  *      request with priority %EFX_FILTER_PRI_MANUAL will reset the
86  *      steering (but not remove the filter).
87  * @EFX_FILTER_FLAG_RX: Filter is for RX
88  * @EFX_FILTER_FLAG_TX: Filter is for TX
89  */
90 enum efx_filter_flags {
91         EFX_FILTER_FLAG_RX_RSS = 0x01,
92         EFX_FILTER_FLAG_RX_SCATTER = 0x02,
93         EFX_FILTER_FLAG_RX_STACK = 0x04,
94         EFX_FILTER_FLAG_RX = 0x08,
95         EFX_FILTER_FLAG_TX = 0x10,
96 };
97
98 /**
99  * struct efx_filter_spec - specification for a hardware filter
100  * @match_flags: Match type flags, from &enum efx_filter_match_flags
101  * @priority: Priority of the filter, from &enum efx_filter_priority
102  * @flags: Miscellaneous flags, from &enum efx_filter_flags
103  * @rss_context: RSS context to use, if %EFX_FILTER_FLAG_RX_RSS is set
104  * @dmaq_id: Source/target queue index, or %EFX_FILTER_RX_DMAQ_ID_DROP for
105  *      an RX drop filter
106  * @outer_vid: Outer VLAN ID to match, if %EFX_FILTER_MATCH_OUTER_VID is set
107  * @inner_vid: Inner VLAN ID to match, if %EFX_FILTER_MATCH_INNER_VID is set
108  * @loc_mac: Local MAC address to match, if %EFX_FILTER_MATCH_LOC_MAC or
109  *      %EFX_FILTER_MATCH_LOC_MAC_IG is set
110  * @rem_mac: Remote MAC address to match, if %EFX_FILTER_MATCH_REM_MAC is set
111  * @ether_type: Ether-type to match, if %EFX_FILTER_MATCH_ETHER_TYPE is set
112  * @ip_proto: IP transport protocol to match, if %EFX_FILTER_MATCH_IP_PROTO
113  *      is set
114  * @loc_host: Local IP host to match, if %EFX_FILTER_MATCH_LOC_HOST is set
115  * @rem_host: Remote IP host to match, if %EFX_FILTER_MATCH_REM_HOST is set
116  * @loc_port: Local TCP/UDP port to match, if %EFX_FILTER_MATCH_LOC_PORT is set
117  * @rem_port: Remote TCP/UDP port to match, if %EFX_FILTER_MATCH_REM_PORT is set
118  *
119  * The efx_filter_init_rx() or efx_filter_init_tx() function *must* be
120  * used to initialise the structure.  The efx_filter_set_*() functions
121  * may then be used to set @rss_context, @match_flags and related
122  * fields.
123  *
124  * The @priority field is used by software to determine whether a new
125  * filter may replace an old one.  The hardware priority of a filter
126  * depends on which fields are matched.
127  */
128 struct efx_filter_spec {
129         u32     match_flags:12;
130         u32     priority:2;
131         u32     flags:6;
132         u32     dmaq_id:12;
133         u32     rss_context;
134         __be16  outer_vid __aligned(4); /* allow jhash2() of match values */
135         __be16  inner_vid;
136         u8      loc_mac[ETH_ALEN];
137         u8      rem_mac[ETH_ALEN];
138         __be16  ether_type;
139         u8      ip_proto;
140         __be32  loc_host[4];
141         __be32  rem_host[4];
142         __be16  loc_port;
143         __be16  rem_port;
144         /* total 64 bytes */
145 };
146
147 enum {
148         EFX_FILTER_RSS_CONTEXT_DEFAULT = 0xffffffff,
149         EFX_FILTER_RX_DMAQ_ID_DROP = 0xfff
150 };
151
152 static inline void efx_filter_init_rx(struct efx_filter_spec *spec,
153                                       enum efx_filter_priority priority,
154                                       enum efx_filter_flags flags,
155                                       unsigned rxq_id)
156 {
157         memset(spec, 0, sizeof(*spec));
158         spec->priority = priority;
159         spec->flags = EFX_FILTER_FLAG_RX | flags;
160         spec->rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
161         spec->dmaq_id = rxq_id;
162 }
163
164 static inline void efx_filter_init_tx(struct efx_filter_spec *spec,
165                                       unsigned txq_id)
166 {
167         memset(spec, 0, sizeof(*spec));
168         spec->priority = EFX_FILTER_PRI_REQUIRED;
169         spec->flags = EFX_FILTER_FLAG_TX;
170         spec->dmaq_id = txq_id;
171 }
172
173 /**
174  * efx_filter_set_ipv4_local - specify IPv4 host, transport protocol and port
175  * @spec: Specification to initialise
176  * @proto: Transport layer protocol number
177  * @host: Local host address (network byte order)
178  * @port: Local port (network byte order)
179  */
180 static inline int
181 efx_filter_set_ipv4_local(struct efx_filter_spec *spec, u8 proto,
182                           __be32 host, __be16 port)
183 {
184         spec->match_flags |=
185                 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
186                 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT;
187         spec->ether_type = htons(ETH_P_IP);
188         spec->ip_proto = proto;
189         spec->loc_host[0] = host;
190         spec->loc_port = port;
191         return 0;
192 }
193
194 /**
195  * efx_filter_set_ipv4_full - specify IPv4 hosts, transport protocol and ports
196  * @spec: Specification to initialise
197  * @proto: Transport layer protocol number
198  * @lhost: Local host address (network byte order)
199  * @lport: Local port (network byte order)
200  * @rhost: Remote host address (network byte order)
201  * @rport: Remote port (network byte order)
202  */
203 static inline int
204 efx_filter_set_ipv4_full(struct efx_filter_spec *spec, u8 proto,
205                          __be32 lhost, __be16 lport,
206                          __be32 rhost, __be16 rport)
207 {
208         spec->match_flags |=
209                 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
210                 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT |
211                 EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_REM_PORT;
212         spec->ether_type = htons(ETH_P_IP);
213         spec->ip_proto = proto;
214         spec->loc_host[0] = lhost;
215         spec->loc_port = lport;
216         spec->rem_host[0] = rhost;
217         spec->rem_port = rport;
218         return 0;
219 }
220
221 enum {
222         EFX_FILTER_VID_UNSPEC = 0xffff,
223 };
224
225 /**
226  * efx_filter_set_eth_local - specify local Ethernet address and/or VID
227  * @spec: Specification to initialise
228  * @vid: Outer VLAN ID to match, or %EFX_FILTER_VID_UNSPEC
229  * @addr: Local Ethernet MAC address, or %NULL
230  */
231 static inline int efx_filter_set_eth_local(struct efx_filter_spec *spec,
232                                            u16 vid, const u8 *addr)
233 {
234         if (vid == EFX_FILTER_VID_UNSPEC && addr == NULL)
235                 return -EINVAL;
236
237         if (vid != EFX_FILTER_VID_UNSPEC) {
238                 spec->match_flags |= EFX_FILTER_MATCH_OUTER_VID;
239                 spec->outer_vid = htons(vid);
240         }
241         if (addr != NULL) {
242                 spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC;
243                 memcpy(spec->loc_mac, addr, ETH_ALEN);
244         }
245         return 0;
246 }
247
248 /**
249  * efx_filter_set_uc_def - specify matching otherwise-unmatched unicast
250  * @spec: Specification to initialise
251  */
252 static inline int efx_filter_set_uc_def(struct efx_filter_spec *spec)
253 {
254         spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
255         return 0;
256 }
257
258 /**
259  * efx_filter_set_mc_def - specify matching otherwise-unmatched multicast
260  * @spec: Specification to initialise
261  */
262 static inline int efx_filter_set_mc_def(struct efx_filter_spec *spec)
263 {
264         spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
265         spec->loc_mac[0] = 1;
266         return 0;
267 }
268
269 #endif /* EFX_FILTER_H */