linux/drivers/net/ethernet/sfc/falcon/filter.h
<<
>>
Prefs
   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 EF4_FILTER_H
  11#define EF4_FILTER_H
  12
  13#include <linux/types.h>
  14#include <linux/if_ether.h>
  15#include <asm/byteorder.h>
  16
  17/**
  18 * enum ef4_filter_match_flags - Flags for hardware filter match type
  19 * @EF4_FILTER_MATCH_REM_HOST: Match by remote IP host address
  20 * @EF4_FILTER_MATCH_LOC_HOST: Match by local IP host address
  21 * @EF4_FILTER_MATCH_REM_MAC: Match by remote MAC address
  22 * @EF4_FILTER_MATCH_REM_PORT: Match by remote TCP/UDP port
  23 * @EF4_FILTER_MATCH_LOC_MAC: Match by local MAC address
  24 * @EF4_FILTER_MATCH_LOC_PORT: Match by local TCP/UDP port
  25 * @EF4_FILTER_MATCH_ETHER_TYPE: Match by Ether-type
  26 * @EF4_FILTER_MATCH_INNER_VID: Match by inner VLAN ID
  27 * @EF4_FILTER_MATCH_OUTER_VID: Match by outer VLAN ID
  28 * @EF4_FILTER_MATCH_IP_PROTO: Match by IP transport protocol
  29 * @EF4_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 */
  45enum ef4_filter_match_flags {
  46        EF4_FILTER_MATCH_REM_HOST =     0x0001,
  47        EF4_FILTER_MATCH_LOC_HOST =     0x0002,
  48        EF4_FILTER_MATCH_REM_MAC =      0x0004,
  49        EF4_FILTER_MATCH_REM_PORT =     0x0008,
  50        EF4_FILTER_MATCH_LOC_MAC =      0x0010,
  51        EF4_FILTER_MATCH_LOC_PORT =     0x0020,
  52        EF4_FILTER_MATCH_ETHER_TYPE =   0x0040,
  53        EF4_FILTER_MATCH_INNER_VID =    0x0080,
  54        EF4_FILTER_MATCH_OUTER_VID =    0x0100,
  55        EF4_FILTER_MATCH_IP_PROTO =     0x0200,
  56        EF4_FILTER_MATCH_LOC_MAC_IG =   0x0400,
  57};
  58
  59/**
  60 * enum ef4_filter_priority - priority of a hardware filter specification
  61 * @EF4_FILTER_PRI_HINT: Performance hint
  62 * @EF4_FILTER_PRI_AUTO: Automatic filter based on device address list
  63 *      or hardware requirements.  This may only be used by the filter
  64 *      implementation for each NIC type.
  65 * @EF4_FILTER_PRI_MANUAL: Manually configured filter
  66 * @EF4_FILTER_PRI_REQUIRED: Required for correct behaviour (user-level
  67 *      networking and SR-IOV)
  68 */
  69enum ef4_filter_priority {
  70        EF4_FILTER_PRI_HINT = 0,
  71        EF4_FILTER_PRI_AUTO,
  72        EF4_FILTER_PRI_MANUAL,
  73        EF4_FILTER_PRI_REQUIRED,
  74};
  75
  76/**
  77 * enum ef4_filter_flags - flags for hardware filter specifications
  78 * @EF4_FILTER_FLAG_RX_RSS: Use RSS to spread across multiple queues.
  79 *      By default, matching packets will be delivered only to the
  80 *      specified queue. If this flag is set, they will be delivered
  81 *      to a range of queues offset from the specified queue number
  82 *      according to the indirection table.
  83 * @EF4_FILTER_FLAG_RX_SCATTER: Enable DMA scatter on the receiving
  84 *      queue.
  85 * @EF4_FILTER_FLAG_RX_OVER_AUTO: Indicates a filter that is
  86 *      overriding an automatic filter (priority
  87 *      %EF4_FILTER_PRI_AUTO).  This may only be set by the filter
  88 *      implementation for each type.  A removal request will restore
  89 *      the automatic filter in its place.
  90 * @EF4_FILTER_FLAG_RX: Filter is for RX
  91 * @EF4_FILTER_FLAG_TX: Filter is for TX
  92 */
  93enum ef4_filter_flags {
  94        EF4_FILTER_FLAG_RX_RSS = 0x01,
  95        EF4_FILTER_FLAG_RX_SCATTER = 0x02,
  96        EF4_FILTER_FLAG_RX_OVER_AUTO = 0x04,
  97        EF4_FILTER_FLAG_RX = 0x08,
  98        EF4_FILTER_FLAG_TX = 0x10,
  99};
 100
 101/**
 102 * struct ef4_filter_spec - specification for a hardware filter
 103 * @match_flags: Match type flags, from &enum ef4_filter_match_flags
 104 * @priority: Priority of the filter, from &enum ef4_filter_priority
 105 * @flags: Miscellaneous flags, from &enum ef4_filter_flags
 106 * @rss_context: RSS context to use, if %EF4_FILTER_FLAG_RX_RSS is set
 107 * @dmaq_id: Source/target queue index, or %EF4_FILTER_RX_DMAQ_ID_DROP for
 108 *      an RX drop filter
 109 * @outer_vid: Outer VLAN ID to match, if %EF4_FILTER_MATCH_OUTER_VID is set
 110 * @inner_vid: Inner VLAN ID to match, if %EF4_FILTER_MATCH_INNER_VID is set
 111 * @loc_mac: Local MAC address to match, if %EF4_FILTER_MATCH_LOC_MAC or
 112 *      %EF4_FILTER_MATCH_LOC_MAC_IG is set
 113 * @rem_mac: Remote MAC address to match, if %EF4_FILTER_MATCH_REM_MAC is set
 114 * @ether_type: Ether-type to match, if %EF4_FILTER_MATCH_ETHER_TYPE is set
 115 * @ip_proto: IP transport protocol to match, if %EF4_FILTER_MATCH_IP_PROTO
 116 *      is set
 117 * @loc_host: Local IP host to match, if %EF4_FILTER_MATCH_LOC_HOST is set
 118 * @rem_host: Remote IP host to match, if %EF4_FILTER_MATCH_REM_HOST is set
 119 * @loc_port: Local TCP/UDP port to match, if %EF4_FILTER_MATCH_LOC_PORT is set
 120 * @rem_port: Remote TCP/UDP port to match, if %EF4_FILTER_MATCH_REM_PORT is set
 121 *
 122 * The ef4_filter_init_rx() or ef4_filter_init_tx() function *must* be
 123 * used to initialise the structure.  The ef4_filter_set_*() functions
 124 * may then be used to set @rss_context, @match_flags and related
 125 * fields.
 126 *
 127 * The @priority field is used by software to determine whether a new
 128 * filter may replace an old one.  The hardware priority of a filter
 129 * depends on which fields are matched.
 130 */
 131struct ef4_filter_spec {
 132        u32     match_flags:12;
 133        u32     priority:2;
 134        u32     flags:6;
 135        u32     dmaq_id:12;
 136        u32     rss_context;
 137        __be16  outer_vid __aligned(4); /* allow jhash2() of match values */
 138        __be16  inner_vid;
 139        u8      loc_mac[ETH_ALEN];
 140        u8      rem_mac[ETH_ALEN];
 141        __be16  ether_type;
 142        u8      ip_proto;
 143        __be32  loc_host[4];
 144        __be32  rem_host[4];
 145        __be16  loc_port;
 146        __be16  rem_port;
 147        /* total 64 bytes */
 148};
 149
 150enum {
 151        EF4_FILTER_RSS_CONTEXT_DEFAULT = 0xffffffff,
 152        EF4_FILTER_RX_DMAQ_ID_DROP = 0xfff
 153};
 154
 155static inline void ef4_filter_init_rx(struct ef4_filter_spec *spec,
 156                                      enum ef4_filter_priority priority,
 157                                      enum ef4_filter_flags flags,
 158                                      unsigned rxq_id)
 159{
 160        memset(spec, 0, sizeof(*spec));
 161        spec->priority = priority;
 162        spec->flags = EF4_FILTER_FLAG_RX | flags;
 163        spec->rss_context = EF4_FILTER_RSS_CONTEXT_DEFAULT;
 164        spec->dmaq_id = rxq_id;
 165}
 166
 167static inline void ef4_filter_init_tx(struct ef4_filter_spec *spec,
 168                                      unsigned txq_id)
 169{
 170        memset(spec, 0, sizeof(*spec));
 171        spec->priority = EF4_FILTER_PRI_REQUIRED;
 172        spec->flags = EF4_FILTER_FLAG_TX;
 173        spec->dmaq_id = txq_id;
 174}
 175
 176/**
 177 * ef4_filter_set_ipv4_local - specify IPv4 host, transport protocol and port
 178 * @spec: Specification to initialise
 179 * @proto: Transport layer protocol number
 180 * @host: Local host address (network byte order)
 181 * @port: Local port (network byte order)
 182 */
 183static inline int
 184ef4_filter_set_ipv4_local(struct ef4_filter_spec *spec, u8 proto,
 185                          __be32 host, __be16 port)
 186{
 187        spec->match_flags |=
 188                EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_IP_PROTO |
 189                EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_LOC_PORT;
 190        spec->ether_type = htons(ETH_P_IP);
 191        spec->ip_proto = proto;
 192        spec->loc_host[0] = host;
 193        spec->loc_port = port;
 194        return 0;
 195}
 196
 197/**
 198 * ef4_filter_set_ipv4_full - specify IPv4 hosts, transport protocol and ports
 199 * @spec: Specification to initialise
 200 * @proto: Transport layer protocol number
 201 * @lhost: Local host address (network byte order)
 202 * @lport: Local port (network byte order)
 203 * @rhost: Remote host address (network byte order)
 204 * @rport: Remote port (network byte order)
 205 */
 206static inline int
 207ef4_filter_set_ipv4_full(struct ef4_filter_spec *spec, u8 proto,
 208                         __be32 lhost, __be16 lport,
 209                         __be32 rhost, __be16 rport)
 210{
 211        spec->match_flags |=
 212                EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_IP_PROTO |
 213                EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_LOC_PORT |
 214                EF4_FILTER_MATCH_REM_HOST | EF4_FILTER_MATCH_REM_PORT;
 215        spec->ether_type = htons(ETH_P_IP);
 216        spec->ip_proto = proto;
 217        spec->loc_host[0] = lhost;
 218        spec->loc_port = lport;
 219        spec->rem_host[0] = rhost;
 220        spec->rem_port = rport;
 221        return 0;
 222}
 223
 224enum {
 225        EF4_FILTER_VID_UNSPEC = 0xffff,
 226};
 227
 228/**
 229 * ef4_filter_set_eth_local - specify local Ethernet address and/or VID
 230 * @spec: Specification to initialise
 231 * @vid: Outer VLAN ID to match, or %EF4_FILTER_VID_UNSPEC
 232 * @addr: Local Ethernet MAC address, or %NULL
 233 */
 234static inline int ef4_filter_set_eth_local(struct ef4_filter_spec *spec,
 235                                           u16 vid, const u8 *addr)
 236{
 237        if (vid == EF4_FILTER_VID_UNSPEC && addr == NULL)
 238                return -EINVAL;
 239
 240        if (vid != EF4_FILTER_VID_UNSPEC) {
 241                spec->match_flags |= EF4_FILTER_MATCH_OUTER_VID;
 242                spec->outer_vid = htons(vid);
 243        }
 244        if (addr != NULL) {
 245                spec->match_flags |= EF4_FILTER_MATCH_LOC_MAC;
 246                ether_addr_copy(spec->loc_mac, addr);
 247        }
 248        return 0;
 249}
 250
 251/**
 252 * ef4_filter_set_uc_def - specify matching otherwise-unmatched unicast
 253 * @spec: Specification to initialise
 254 */
 255static inline int ef4_filter_set_uc_def(struct ef4_filter_spec *spec)
 256{
 257        spec->match_flags |= EF4_FILTER_MATCH_LOC_MAC_IG;
 258        return 0;
 259}
 260
 261/**
 262 * ef4_filter_set_mc_def - specify matching otherwise-unmatched multicast
 263 * @spec: Specification to initialise
 264 */
 265static inline int ef4_filter_set_mc_def(struct ef4_filter_spec *spec)
 266{
 267        spec->match_flags |= EF4_FILTER_MATCH_LOC_MAC_IG;
 268        spec->loc_mac[0] = 1;
 269        return 0;
 270}
 271
 272#endif /* EF4_FILTER_H */
 273