blob: 1b410defccecc9a35e445b52ca4fad53e6efef2a [file] [log] [blame]
Ben Hutchings64eebcf2010-09-20 08:43:07 +00001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2010 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>
Ben Hutchings7c460d92012-10-27 00:33:28 +010014#include <linux/if_ether.h>
15#include <asm/byteorder.h>
Ben Hutchings64eebcf2010-09-20 08:43:07 +000016
Ben Hutchings64eebcf2010-09-20 08:43:07 +000017/**
Ben Hutchings7c460d92012-10-27 00:33:28 +010018 * 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.
Ben Hutchings64eebcf2010-09-20 08:43:07 +000031 *
Ben Hutchings7c460d92012-10-27 00:33:28 +010032 * 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
Ben Hutchings64eebcf2010-09-20 08:43:07 +000044 */
Ben Hutchings7c460d92012-10-27 00:33:28 +010045enum 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,
Ben Hutchings64eebcf2010-09-20 08:43:07 +000057};
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
Ben Hutchings3d885e32012-02-06 17:27:52 +000063 * @EFX_FILTER_PRI_REQUIRED: Required for correct behaviour (user-level
64 * networking and SR-IOV)
Ben Hutchings64eebcf2010-09-20 08:43:07 +000065 */
66enum 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.
Ben Hutchingsc39d35e2010-12-07 19:11:26 +000081 * @EFX_FILTER_FLAG_RX: Filter is for RX
Ben Hutchings3d885e32012-02-06 17:27:52 +000082 * @EFX_FILTER_FLAG_TX: Filter is for TX
Ben Hutchings64eebcf2010-09-20 08:43:07 +000083 */
84enum efx_filter_flags {
85 EFX_FILTER_FLAG_RX_RSS = 0x01,
86 EFX_FILTER_FLAG_RX_SCATTER = 0x02,
Ben Hutchingsc39d35e2010-12-07 19:11:26 +000087 EFX_FILTER_FLAG_RX = 0x08,
Ben Hutchings3d885e32012-02-06 17:27:52 +000088 EFX_FILTER_FLAG_TX = 0x10,
Ben Hutchings64eebcf2010-09-20 08:43:07 +000089};
90
91/**
92 * struct efx_filter_spec - specification for a hardware filter
Ben Hutchings7c460d92012-10-27 00:33:28 +010093 * @match_flags: Match type flags, from &enum efx_filter_match_flags
Ben Hutchings64eebcf2010-09-20 08:43:07 +000094 * @priority: Priority of the filter, from &enum efx_filter_priority
95 * @flags: Miscellaneous flags, from &enum efx_filter_flags
Ben Hutchings7c460d92012-10-27 00:33:28 +010096 * @rss_context: RSS context to use, if %EFX_FILTER_FLAG_RX_RSS is set
Ben Hutchingsf26e9582012-10-30 01:01:52 +000097 * @dmaq_id: Source/target queue index, or %EFX_FILTER_RX_DMAQ_ID_DROP for
98 * an RX drop filter
Ben Hutchings7c460d92012-10-27 00:33:28 +010099 * @outer_vid: Outer VLAN ID to match, if %EFX_FILTER_MATCH_OUTER_VID is set
100 * @inner_vid: Inner VLAN ID to match, if %EFX_FILTER_MATCH_INNER_VID is set
101 * @loc_mac: Local MAC address to match, if %EFX_FILTER_MATCH_LOC_MAC or
102 * %EFX_FILTER_MATCH_LOC_MAC_IG is set
103 * @rem_mac: Remote MAC address to match, if %EFX_FILTER_MATCH_REM_MAC is set
104 * @ether_type: Ether-type to match, if %EFX_FILTER_MATCH_ETHER_TYPE is set
105 * @ip_proto: IP transport protocol to match, if %EFX_FILTER_MATCH_IP_PROTO
106 * is set
107 * @loc_host: Local IP host to match, if %EFX_FILTER_MATCH_LOC_HOST is set
108 * @rem_host: Remote IP host to match, if %EFX_FILTER_MATCH_REM_HOST is set
109 * @loc_port: Local TCP/UDP port to match, if %EFX_FILTER_MATCH_LOC_PORT is set
110 * @rem_port: Remote TCP/UDP port to match, if %EFX_FILTER_MATCH_REM_PORT is set
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000111 *
Ben Hutchings7c460d92012-10-27 00:33:28 +0100112 * The efx_filter_init_rx() or efx_filter_init_tx() function *must* be
113 * used to initialise the structure. The efx_filter_set_*() functions
114 * may then be used to set @rss_context, @match_flags and related
115 * fields.
Ben Hutchingsb1f92842012-01-03 12:05:15 +0000116 *
117 * The @priority field is used by software to determine whether a new
118 * filter may replace an old one. The hardware priority of a filter
Ben Hutchings7c460d92012-10-27 00:33:28 +0100119 * depends on which fields are matched.
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000120 */
121struct efx_filter_spec {
Ben Hutchings7c460d92012-10-27 00:33:28 +0100122 u32 match_flags:12;
123 u32 priority:2;
124 u32 flags:6;
125 u32 dmaq_id:12;
126 u32 rss_context;
127 __be16 outer_vid __aligned(4); /* allow jhash2() of match values */
128 __be16 inner_vid;
129 u8 loc_mac[ETH_ALEN];
130 u8 rem_mac[ETH_ALEN];
131 __be16 ether_type;
132 u8 ip_proto;
133 __be32 loc_host[4];
134 __be32 rem_host[4];
135 __be16 loc_port;
136 __be16 rem_port;
137 /* total 64 bytes */
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000138};
139
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000140enum {
Ben Hutchings7c460d92012-10-27 00:33:28 +0100141 EFX_FILTER_RSS_CONTEXT_DEFAULT = 0xffffffff,
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000142 EFX_FILTER_RX_DMAQ_ID_DROP = 0xfff
143};
144
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000145static inline void efx_filter_init_rx(struct efx_filter_spec *spec,
146 enum efx_filter_priority priority,
147 enum efx_filter_flags flags,
148 unsigned rxq_id)
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000149{
Ben Hutchings7c460d92012-10-27 00:33:28 +0100150 memset(spec, 0, sizeof(*spec));
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000151 spec->priority = priority;
152 spec->flags = EFX_FILTER_FLAG_RX | flags;
Ben Hutchings7c460d92012-10-27 00:33:28 +0100153 spec->rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000154 spec->dmaq_id = rxq_id;
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000155}
156
Ben Hutchings3d885e32012-02-06 17:27:52 +0000157static inline void efx_filter_init_tx(struct efx_filter_spec *spec,
158 unsigned txq_id)
159{
Ben Hutchings7c460d92012-10-27 00:33:28 +0100160 memset(spec, 0, sizeof(*spec));
Ben Hutchings3d885e32012-02-06 17:27:52 +0000161 spec->priority = EFX_FILTER_PRI_REQUIRED;
162 spec->flags = EFX_FILTER_FLAG_TX;
163 spec->dmaq_id = txq_id;
164}
165
Ben Hutchings7c460d92012-10-27 00:33:28 +0100166/**
167 * efx_filter_set_ipv4_local - specify IPv4 host, transport protocol and port
168 * @spec: Specification to initialise
169 * @proto: Transport layer protocol number
170 * @host: Local host address (network byte order)
171 * @port: Local port (network byte order)
172 */
173static inline int
174efx_filter_set_ipv4_local(struct efx_filter_spec *spec, u8 proto,
175 __be32 host, __be16 port)
176{
177 spec->match_flags |=
178 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
179 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT;
180 spec->ether_type = htons(ETH_P_IP);
181 spec->ip_proto = proto;
182 spec->loc_host[0] = host;
183 spec->loc_port = port;
184 return 0;
185}
186
187/**
188 * efx_filter_set_ipv4_full - specify IPv4 hosts, transport protocol and ports
189 * @spec: Specification to initialise
190 * @proto: Transport layer protocol number
191 * @lhost: Local host address (network byte order)
192 * @lport: Local port (network byte order)
193 * @rhost: Remote host address (network byte order)
194 * @rport: Remote port (network byte order)
195 */
196static inline int
197efx_filter_set_ipv4_full(struct efx_filter_spec *spec, u8 proto,
198 __be32 lhost, __be16 lport,
199 __be32 rhost, __be16 rport)
200{
201 spec->match_flags |=
202 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
203 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT |
204 EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_REM_PORT;
205 spec->ether_type = htons(ETH_P_IP);
206 spec->ip_proto = proto;
207 spec->loc_host[0] = lhost;
208 spec->loc_port = lport;
209 spec->rem_host[0] = rhost;
210 spec->rem_port = rport;
211 return 0;
212}
213
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000214enum {
215 EFX_FILTER_VID_UNSPEC = 0xffff,
216};
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000217
Ben Hutchings7c460d92012-10-27 00:33:28 +0100218/**
219 * efx_filter_set_eth_local - specify local Ethernet address and/or VID
220 * @spec: Specification to initialise
221 * @vid: Outer VLAN ID to match, or %EFX_FILTER_VID_UNSPEC
222 * @addr: Local Ethernet MAC address, or %NULL
223 */
224static inline int efx_filter_set_eth_local(struct efx_filter_spec *spec,
225 u16 vid, const u8 *addr)
226{
227 if (vid == EFX_FILTER_VID_UNSPEC && addr == NULL)
228 return -EINVAL;
229
230 if (vid != EFX_FILTER_VID_UNSPEC) {
231 spec->match_flags |= EFX_FILTER_MATCH_OUTER_VID;
232 spec->outer_vid = htons(vid);
233 }
234 if (addr != NULL) {
235 spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC;
236 memcpy(spec->loc_mac, addr, ETH_ALEN);
237 }
238 return 0;
239}
240
241/**
242 * efx_filter_set_uc_def - specify matching otherwise-unmatched unicast
243 * @spec: Specification to initialise
244 */
245static inline int efx_filter_set_uc_def(struct efx_filter_spec *spec)
246{
247 spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
248 return 0;
249}
250
251/**
252 * efx_filter_set_mc_def - specify matching otherwise-unmatched multicast
253 * @spec: Specification to initialise
254 */
255static inline int efx_filter_set_mc_def(struct efx_filter_spec *spec)
256{
257 spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
258 spec->loc_mac[0] = 1;
259 return 0;
260}
261
Ben Hutchings64eebcf2010-09-20 08:43:07 +0000262#endif /* EFX_FILTER_H */