Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /****************************************************************************
0003  * Driver for Solarflare network controllers and boards
0004  * Copyright 2005-2013 Solarflare Communications Inc.
0005  */
0006 
0007 #ifndef EFX_FILTER_H
0008 #define EFX_FILTER_H
0009 
0010 #include <linux/types.h>
0011 #include <linux/if_ether.h>
0012 #include <asm/byteorder.h>
0013 
0014 /**
0015  * enum efx_filter_match_flags - Flags for hardware filter match type
0016  * @EFX_FILTER_MATCH_REM_HOST: Match by remote IP host address
0017  * @EFX_FILTER_MATCH_LOC_HOST: Match by local IP host address
0018  * @EFX_FILTER_MATCH_REM_MAC: Match by remote MAC address
0019  * @EFX_FILTER_MATCH_REM_PORT: Match by remote TCP/UDP port
0020  * @EFX_FILTER_MATCH_LOC_MAC: Match by local MAC address
0021  * @EFX_FILTER_MATCH_LOC_PORT: Match by local TCP/UDP port
0022  * @EFX_FILTER_MATCH_ETHER_TYPE: Match by Ether-type
0023  * @EFX_FILTER_MATCH_INNER_VID: Match by inner VLAN ID
0024  * @EFX_FILTER_MATCH_OUTER_VID: Match by outer VLAN ID
0025  * @EFX_FILTER_MATCH_IP_PROTO: Match by IP transport protocol
0026  * @EFX_FILTER_MATCH_LOC_MAC_IG: Match by local MAC address I/G bit.
0027  * @EFX_FILTER_MATCH_ENCAP_TYPE: Match by encapsulation type.
0028  *  Used for RX default unicast and multicast/broadcast filters.
0029  *
0030  * Only some combinations are supported, depending on NIC type:
0031  *
0032  * - Falcon supports RX filters matching by {TCP,UDP}/IPv4 4-tuple or
0033  *   local 2-tuple (only implemented for Falcon B0)
0034  *
0035  * - Siena supports RX and TX filters matching by {TCP,UDP}/IPv4 4-tuple
0036  *   or local 2-tuple, or local MAC with or without outer VID, and RX
0037  *   default filters
0038  *
0039  * - Huntington supports filter matching controlled by firmware, potentially
0040  *   using {TCP,UDP}/IPv{4,6} 4-tuple or local 2-tuple, local MAC or I/G bit,
0041  *   with or without outer and inner VID
0042  */
0043 enum efx_filter_match_flags {
0044     EFX_FILTER_MATCH_REM_HOST = 0x0001,
0045     EFX_FILTER_MATCH_LOC_HOST = 0x0002,
0046     EFX_FILTER_MATCH_REM_MAC =  0x0004,
0047     EFX_FILTER_MATCH_REM_PORT = 0x0008,
0048     EFX_FILTER_MATCH_LOC_MAC =  0x0010,
0049     EFX_FILTER_MATCH_LOC_PORT = 0x0020,
0050     EFX_FILTER_MATCH_ETHER_TYPE =   0x0040,
0051     EFX_FILTER_MATCH_INNER_VID =    0x0080,
0052     EFX_FILTER_MATCH_OUTER_VID =    0x0100,
0053     EFX_FILTER_MATCH_IP_PROTO = 0x0200,
0054     EFX_FILTER_MATCH_LOC_MAC_IG =   0x0400,
0055     EFX_FILTER_MATCH_ENCAP_TYPE =   0x0800,
0056 };
0057 
0058 /**
0059  * enum efx_filter_priority - priority of a hardware filter specification
0060  * @EFX_FILTER_PRI_HINT: Performance hint
0061  * @EFX_FILTER_PRI_AUTO: Automatic filter based on device address list
0062  *  or hardware requirements.  This may only be used by the filter
0063  *  implementation for each NIC type.
0064  * @EFX_FILTER_PRI_MANUAL: Manually configured filter
0065  * @EFX_FILTER_PRI_REQUIRED: Required for correct behaviour (user-level
0066  *  networking and SR-IOV)
0067  */
0068 enum efx_filter_priority {
0069     EFX_FILTER_PRI_HINT = 0,
0070     EFX_FILTER_PRI_AUTO,
0071     EFX_FILTER_PRI_MANUAL,
0072     EFX_FILTER_PRI_REQUIRED,
0073 };
0074 
0075 /**
0076  * enum efx_filter_flags - flags for hardware filter specifications
0077  * @EFX_FILTER_FLAG_RX_RSS: Use RSS to spread across multiple queues.
0078  *  By default, matching packets will be delivered only to the
0079  *  specified queue. If this flag is set, they will be delivered
0080  *  to a range of queues offset from the specified queue number
0081  *  according to the indirection table.
0082  * @EFX_FILTER_FLAG_RX_SCATTER: Enable DMA scatter on the receiving
0083  *  queue.
0084  * @EFX_FILTER_FLAG_RX_OVER_AUTO: Indicates a filter that is
0085  *  overriding an automatic filter (priority
0086  *  %EFX_FILTER_PRI_AUTO).  This may only be set by the filter
0087  *  implementation for each type.  A removal request will restore
0088  *  the automatic filter in its place.
0089  * @EFX_FILTER_FLAG_RX: Filter is for RX
0090  * @EFX_FILTER_FLAG_TX: Filter is for TX
0091  * @EFX_FILTER_FLAG_VPORT_ID: Virtual port ID for adapter switching.
0092  */
0093 enum efx_filter_flags {
0094     EFX_FILTER_FLAG_RX_RSS = 0x01,
0095     EFX_FILTER_FLAG_RX_SCATTER = 0x02,
0096     EFX_FILTER_FLAG_RX_OVER_AUTO = 0x04,
0097     EFX_FILTER_FLAG_RX = 0x08,
0098     EFX_FILTER_FLAG_TX = 0x10,
0099     EFX_FILTER_FLAG_VPORT_ID = 0x20,
0100 };
0101 
0102 /** enum efx_encap_type - types of encapsulation
0103  * @EFX_ENCAP_TYPE_NONE: no encapsulation
0104  * @EFX_ENCAP_TYPE_VXLAN: VXLAN encapsulation
0105  * @EFX_ENCAP_TYPE_NVGRE: NVGRE encapsulation
0106  * @EFX_ENCAP_TYPE_GENEVE: GENEVE encapsulation
0107  * @EFX_ENCAP_FLAG_IPV6: indicates IPv6 outer frame
0108  *
0109  * Contains both enumerated types and flags.
0110  * To get just the type, OR with @EFX_ENCAP_TYPES_MASK.
0111  */
0112 enum efx_encap_type {
0113     EFX_ENCAP_TYPE_NONE = 0,
0114     EFX_ENCAP_TYPE_VXLAN = 1,
0115     EFX_ENCAP_TYPE_NVGRE = 2,
0116     EFX_ENCAP_TYPE_GENEVE = 3,
0117 
0118     EFX_ENCAP_TYPES_MASK = 7,
0119     EFX_ENCAP_FLAG_IPV6 = 8,
0120 };
0121 
0122 /**
0123  * struct efx_filter_spec - specification for a hardware filter
0124  * @match_flags: Match type flags, from &enum efx_filter_match_flags
0125  * @priority: Priority of the filter, from &enum efx_filter_priority
0126  * @flags: Miscellaneous flags, from &enum efx_filter_flags
0127  * @rss_context: RSS context to use, if %EFX_FILTER_FLAG_RX_RSS is set.  This
0128  *  is a user_id (with 0 meaning the driver/default RSS context), not an
0129  *  MCFW context_id.
0130  * @dmaq_id: Source/target queue index, or %EFX_FILTER_RX_DMAQ_ID_DROP for
0131  *  an RX drop filter
0132  * @vport_id: Virtual port ID associated with RX queue, for adapter switching,
0133  *  if %EFX_FILTER_FLAG_VPORT_ID is set.  This is an MCFW vport_id, or on
0134  *  EF100 an mport selector.
0135  * @outer_vid: Outer VLAN ID to match, if %EFX_FILTER_MATCH_OUTER_VID is set
0136  * @inner_vid: Inner VLAN ID to match, if %EFX_FILTER_MATCH_INNER_VID is set
0137  * @loc_mac: Local MAC address to match, if %EFX_FILTER_MATCH_LOC_MAC or
0138  *  %EFX_FILTER_MATCH_LOC_MAC_IG is set
0139  * @rem_mac: Remote MAC address to match, if %EFX_FILTER_MATCH_REM_MAC is set
0140  * @ether_type: Ether-type to match, if %EFX_FILTER_MATCH_ETHER_TYPE is set
0141  * @ip_proto: IP transport protocol to match, if %EFX_FILTER_MATCH_IP_PROTO
0142  *  is set
0143  * @loc_host: Local IP host to match, if %EFX_FILTER_MATCH_LOC_HOST is set
0144  * @rem_host: Remote IP host to match, if %EFX_FILTER_MATCH_REM_HOST is set
0145  * @loc_port: Local TCP/UDP port to match, if %EFX_FILTER_MATCH_LOC_PORT is set
0146  * @rem_port: Remote TCP/UDP port to match, if %EFX_FILTER_MATCH_REM_PORT is set
0147  * @encap_type: Encapsulation type to match (from &enum efx_encap_type), if
0148  *  %EFX_FILTER_MATCH_ENCAP_TYPE is set
0149  *
0150  * The efx_filter_init_rx() or efx_filter_init_tx() function *must* be
0151  * used to initialise the structure.  The efx_filter_set_*() functions
0152  * may then be used to set @rss_context, @match_flags and related
0153  * fields.
0154  *
0155  * The @priority field is used by software to determine whether a new
0156  * filter may replace an old one.  The hardware priority of a filter
0157  * depends on which fields are matched.
0158  */
0159 struct efx_filter_spec {
0160     u32 match_flags:12;
0161     u32 priority:2;
0162     u32 flags:6;
0163     u32 dmaq_id:12;
0164     u32 vport_id;
0165     u32 rss_context;
0166     __be16  outer_vid __aligned(4); /* allow jhash2() of match values */
0167     __be16  inner_vid;
0168     u8  loc_mac[ETH_ALEN];
0169     u8  rem_mac[ETH_ALEN];
0170     __be16  ether_type;
0171     u8  ip_proto;
0172     __be32  loc_host[4];
0173     __be32  rem_host[4];
0174     __be16  loc_port;
0175     __be16  rem_port;
0176     u32     encap_type:4;
0177     /* total 65 bytes */
0178 };
0179 
0180 enum {
0181     EFX_FILTER_RX_DMAQ_ID_DROP = 0xfff
0182 };
0183 
0184 static inline void efx_filter_init_rx(struct efx_filter_spec *spec,
0185                       enum efx_filter_priority priority,
0186                       enum efx_filter_flags flags,
0187                       unsigned rxq_id)
0188 {
0189     memset(spec, 0, sizeof(*spec));
0190     spec->priority = priority;
0191     spec->flags = EFX_FILTER_FLAG_RX | flags;
0192     spec->rss_context = 0;
0193     spec->dmaq_id = rxq_id;
0194 }
0195 
0196 static inline void efx_filter_init_tx(struct efx_filter_spec *spec,
0197                       unsigned txq_id)
0198 {
0199     memset(spec, 0, sizeof(*spec));
0200     spec->priority = EFX_FILTER_PRI_REQUIRED;
0201     spec->flags = EFX_FILTER_FLAG_TX;
0202     spec->dmaq_id = txq_id;
0203 }
0204 
0205 /**
0206  * efx_filter_set_ipv4_local - specify IPv4 host, transport protocol and port
0207  * @spec: Specification to initialise
0208  * @proto: Transport layer protocol number
0209  * @host: Local host address (network byte order)
0210  * @port: Local port (network byte order)
0211  */
0212 static inline int
0213 efx_filter_set_ipv4_local(struct efx_filter_spec *spec, u8 proto,
0214               __be32 host, __be16 port)
0215 {
0216     spec->match_flags |=
0217         EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
0218         EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT;
0219     spec->ether_type = htons(ETH_P_IP);
0220     spec->ip_proto = proto;
0221     spec->loc_host[0] = host;
0222     spec->loc_port = port;
0223     return 0;
0224 }
0225 
0226 /**
0227  * efx_filter_set_ipv4_full - specify IPv4 hosts, transport protocol and ports
0228  * @spec: Specification to initialise
0229  * @proto: Transport layer protocol number
0230  * @lhost: Local host address (network byte order)
0231  * @lport: Local port (network byte order)
0232  * @rhost: Remote host address (network byte order)
0233  * @rport: Remote port (network byte order)
0234  */
0235 static inline int
0236 efx_filter_set_ipv4_full(struct efx_filter_spec *spec, u8 proto,
0237              __be32 lhost, __be16 lport,
0238              __be32 rhost, __be16 rport)
0239 {
0240     spec->match_flags |=
0241         EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
0242         EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT |
0243         EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_REM_PORT;
0244     spec->ether_type = htons(ETH_P_IP);
0245     spec->ip_proto = proto;
0246     spec->loc_host[0] = lhost;
0247     spec->loc_port = lport;
0248     spec->rem_host[0] = rhost;
0249     spec->rem_port = rport;
0250     return 0;
0251 }
0252 
0253 enum {
0254     EFX_FILTER_VID_UNSPEC = 0xffff,
0255 };
0256 
0257 /**
0258  * efx_filter_set_eth_local - specify local Ethernet address and/or VID
0259  * @spec: Specification to initialise
0260  * @vid: Outer VLAN ID to match, or %EFX_FILTER_VID_UNSPEC
0261  * @addr: Local Ethernet MAC address, or %NULL
0262  */
0263 static inline int efx_filter_set_eth_local(struct efx_filter_spec *spec,
0264                        u16 vid, const u8 *addr)
0265 {
0266     if (vid == EFX_FILTER_VID_UNSPEC && addr == NULL)
0267         return -EINVAL;
0268 
0269     if (vid != EFX_FILTER_VID_UNSPEC) {
0270         spec->match_flags |= EFX_FILTER_MATCH_OUTER_VID;
0271         spec->outer_vid = htons(vid);
0272     }
0273     if (addr != NULL) {
0274         spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC;
0275         ether_addr_copy(spec->loc_mac, addr);
0276     }
0277     return 0;
0278 }
0279 
0280 /**
0281  * efx_filter_set_uc_def - specify matching otherwise-unmatched unicast
0282  * @spec: Specification to initialise
0283  */
0284 static inline int efx_filter_set_uc_def(struct efx_filter_spec *spec)
0285 {
0286     spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
0287     return 0;
0288 }
0289 
0290 /**
0291  * efx_filter_set_mc_def - specify matching otherwise-unmatched multicast
0292  * @spec: Specification to initialise
0293  */
0294 static inline int efx_filter_set_mc_def(struct efx_filter_spec *spec)
0295 {
0296     spec->match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
0297     spec->loc_mac[0] = 1;
0298     return 0;
0299 }
0300 
0301 /**
0302  * efx_filter_set_vport_id - override virtual port id relating to filter
0303  * @spec: Specification to initialise
0304  * @vport_id: firmware ID of the virtual port
0305  */
0306 static inline void efx_filter_set_vport_id(struct efx_filter_spec *spec,
0307                        u32 vport_id)
0308 {
0309     spec->flags |= EFX_FILTER_FLAG_VPORT_ID;
0310     spec->vport_id = vport_id;
0311 }
0312 
0313 static inline void efx_filter_set_encap_type(struct efx_filter_spec *spec,
0314                          enum efx_encap_type encap_type)
0315 {
0316     spec->match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
0317     spec->encap_type = encap_type;
0318 }
0319 
0320 static inline enum efx_encap_type efx_filter_get_encap_type(
0321         const struct efx_filter_spec *spec)
0322 {
0323     if (spec->match_flags & EFX_FILTER_MATCH_ENCAP_TYPE)
0324         return spec->encap_type;
0325     return EFX_ENCAP_TYPE_NONE;
0326 }
0327 #endif /* EFX_FILTER_H */