Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
| 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> |
| 14 | |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 15 | /** |
| 16 | * enum efx_filter_type - type of hardware filter |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 17 | * @EFX_FILTER_TCP_FULL: Matching TCP/IPv4 4-tuple |
| 18 | * @EFX_FILTER_TCP_WILD: Matching TCP/IPv4 destination (host, port) |
| 19 | * @EFX_FILTER_UDP_FULL: Matching UDP/IPv4 4-tuple |
| 20 | * @EFX_FILTER_UDP_WILD: Matching UDP/IPv4 destination (host, port) |
| 21 | * @EFX_FILTER_MAC_FULL: Matching Ethernet destination MAC address, VID |
| 22 | * @EFX_FILTER_MAC_WILD: Matching Ethernet destination MAC address |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 23 | * @EFX_FILTER_UC_DEF: Matching all otherwise unmatched unicast |
| 24 | * @EFX_FILTER_MC_DEF: Matching all otherwise unmatched multicast |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 25 | * @EFX_FILTER_UNSPEC: Match type is unspecified |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 26 | * |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 27 | * Falcon NICs only support the TCP/IPv4 and UDP/IPv4 filter types. |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 28 | */ |
| 29 | enum efx_filter_type { |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 30 | EFX_FILTER_TCP_FULL = 0, |
| 31 | EFX_FILTER_TCP_WILD, |
| 32 | EFX_FILTER_UDP_FULL, |
| 33 | EFX_FILTER_UDP_WILD, |
| 34 | EFX_FILTER_MAC_FULL = 4, |
| 35 | EFX_FILTER_MAC_WILD, |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 36 | EFX_FILTER_UC_DEF = 8, |
| 37 | EFX_FILTER_MC_DEF, |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 38 | EFX_FILTER_TYPE_COUNT, /* number of specific types */ |
| 39 | EFX_FILTER_UNSPEC = 0xf, |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * enum efx_filter_priority - priority of a hardware filter specification |
| 44 | * @EFX_FILTER_PRI_HINT: Performance hint |
| 45 | * @EFX_FILTER_PRI_MANUAL: Manually configured filter |
Ben Hutchings | 3d885e3 | 2012-02-06 17:27:52 +0000 | [diff] [blame] | 46 | * @EFX_FILTER_PRI_REQUIRED: Required for correct behaviour (user-level |
| 47 | * networking and SR-IOV) |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 48 | */ |
| 49 | enum efx_filter_priority { |
| 50 | EFX_FILTER_PRI_HINT = 0, |
| 51 | EFX_FILTER_PRI_MANUAL, |
| 52 | EFX_FILTER_PRI_REQUIRED, |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * enum efx_filter_flags - flags for hardware filter specifications |
| 57 | * @EFX_FILTER_FLAG_RX_RSS: Use RSS to spread across multiple queues. |
| 58 | * By default, matching packets will be delivered only to the |
| 59 | * specified queue. If this flag is set, they will be delivered |
| 60 | * to a range of queues offset from the specified queue number |
| 61 | * according to the indirection table. |
| 62 | * @EFX_FILTER_FLAG_RX_SCATTER: Enable DMA scatter on the receiving |
| 63 | * queue. |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 64 | * @EFX_FILTER_FLAG_RX: Filter is for RX |
Ben Hutchings | 3d885e3 | 2012-02-06 17:27:52 +0000 | [diff] [blame] | 65 | * @EFX_FILTER_FLAG_TX: Filter is for TX |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 66 | */ |
| 67 | enum efx_filter_flags { |
| 68 | EFX_FILTER_FLAG_RX_RSS = 0x01, |
| 69 | EFX_FILTER_FLAG_RX_SCATTER = 0x02, |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 70 | EFX_FILTER_FLAG_RX = 0x08, |
Ben Hutchings | 3d885e3 | 2012-02-06 17:27:52 +0000 | [diff] [blame] | 71 | EFX_FILTER_FLAG_TX = 0x10, |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * struct efx_filter_spec - specification for a hardware filter |
| 76 | * @type: Type of match to be performed, from &enum efx_filter_type |
| 77 | * @priority: Priority of the filter, from &enum efx_filter_priority |
| 78 | * @flags: Miscellaneous flags, from &enum efx_filter_flags |
Ben Hutchings | f26e958 | 2012-10-30 01:01:52 +0000 | [diff] [blame^] | 79 | * @dmaq_id: Source/target queue index, or %EFX_FILTER_RX_DMAQ_ID_DROP for |
| 80 | * an RX drop filter |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 81 | * @data: Match data (type-dependent) |
| 82 | * |
| 83 | * Use the efx_filter_set_*() functions to initialise the @type and |
| 84 | * @data fields. |
Ben Hutchings | b1f9284 | 2012-01-03 12:05:15 +0000 | [diff] [blame] | 85 | * |
| 86 | * The @priority field is used by software to determine whether a new |
| 87 | * filter may replace an old one. The hardware priority of a filter |
Ben Hutchings | 9e0f9a1 | 2012-09-04 18:57:25 +0100 | [diff] [blame] | 88 | * depends on the filter type. |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 89 | */ |
| 90 | struct efx_filter_spec { |
| 91 | u8 type:4; |
| 92 | u8 priority:4; |
| 93 | u8 flags; |
| 94 | u16 dmaq_id; |
| 95 | u32 data[3]; |
| 96 | }; |
| 97 | |
Ben Hutchings | f26e958 | 2012-10-30 01:01:52 +0000 | [diff] [blame^] | 98 | enum { |
| 99 | EFX_FILTER_RX_DMAQ_ID_DROP = 0xfff |
| 100 | }; |
| 101 | |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 102 | static inline void efx_filter_init_rx(struct efx_filter_spec *spec, |
| 103 | enum efx_filter_priority priority, |
| 104 | enum efx_filter_flags flags, |
| 105 | unsigned rxq_id) |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 106 | { |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 107 | spec->type = EFX_FILTER_UNSPEC; |
| 108 | spec->priority = priority; |
| 109 | spec->flags = EFX_FILTER_FLAG_RX | flags; |
| 110 | spec->dmaq_id = rxq_id; |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Ben Hutchings | 3d885e3 | 2012-02-06 17:27:52 +0000 | [diff] [blame] | 113 | static inline void efx_filter_init_tx(struct efx_filter_spec *spec, |
| 114 | unsigned txq_id) |
| 115 | { |
| 116 | spec->type = EFX_FILTER_UNSPEC; |
| 117 | spec->priority = EFX_FILTER_PRI_REQUIRED; |
| 118 | spec->flags = EFX_FILTER_FLAG_TX; |
| 119 | spec->dmaq_id = txq_id; |
| 120 | } |
| 121 | |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 122 | extern int efx_filter_set_ipv4_local(struct efx_filter_spec *spec, u8 proto, |
| 123 | __be32 host, __be16 port); |
Ben Hutchings | 1a6281a | 2012-01-03 12:05:39 +0000 | [diff] [blame] | 124 | extern int efx_filter_get_ipv4_local(const struct efx_filter_spec *spec, |
| 125 | u8 *proto, __be32 *host, __be16 *port); |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 126 | extern int efx_filter_set_ipv4_full(struct efx_filter_spec *spec, u8 proto, |
| 127 | __be32 host, __be16 port, |
| 128 | __be32 rhost, __be16 rport); |
Ben Hutchings | 1a6281a | 2012-01-03 12:05:39 +0000 | [diff] [blame] | 129 | extern int efx_filter_get_ipv4_full(const struct efx_filter_spec *spec, |
| 130 | u8 *proto, __be32 *host, __be16 *port, |
| 131 | __be32 *rhost, __be16 *rport); |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 132 | extern int efx_filter_set_eth_local(struct efx_filter_spec *spec, |
| 133 | u16 vid, const u8 *addr); |
Ben Hutchings | 1a6281a | 2012-01-03 12:05:39 +0000 | [diff] [blame] | 134 | extern int efx_filter_get_eth_local(const struct efx_filter_spec *spec, |
| 135 | u16 *vid, u8 *addr); |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 136 | extern int efx_filter_set_uc_def(struct efx_filter_spec *spec); |
| 137 | extern int efx_filter_set_mc_def(struct efx_filter_spec *spec); |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 138 | enum { |
| 139 | EFX_FILTER_VID_UNSPEC = 0xffff, |
| 140 | }; |
Ben Hutchings | 64eebcf | 2010-09-20 08:43:07 +0000 | [diff] [blame] | 141 | |
| 142 | #endif /* EFX_FILTER_H */ |