Allocate four bits from the mbuf flags field to represent the hash type of a software- or hardware-generated hash held in the mbuf.m_pkthdr.flowid field, and provide accessor macros to easily clear, set, receive, and test for hash values. Some of these constants correspond to RSS hash types, but we don't want to limit ourselves to that, as a number of other hashing techniques are in use on hardware supported by FreeBSD. Mark the M_FLOWID flag as deprecated; I hope to remove this before 9.0, changing drivers and the stack over to using the new M_HASHTYPEBITS, most likely to use M_HASHTYPE_OPAQUE as we don't yet want to nail down the KPI for RSS key/bucket management for device drivers. MFC after: 3 days Reviewed by: bz Sponsored by: Juniper Networks, Inc. Index: sys/mbuf.h =================================================================== --- sys/mbuf.h (revision 222695) +++ sys/mbuf.h (working copy) @@ -199,7 +199,9 @@ #define M_PROTO6 0x00080000 /* protocol-specific */ #define M_PROTO7 0x00100000 /* protocol-specific */ #define M_PROTO8 0x00200000 /* protocol-specific */ -#define M_FLOWID 0x00400000 /* flowid is valid */ +#define M_FLOWID 0x00400000 /* deprecated: flowid is valid */ +#define M_HASHTYPEBITS 0x0F000000 /* mask of bits holding flowid hash type */ + /* * For RELENG_{6,7} steal these flags for limited multiple routing table * support. In RELENG_8 and beyond, use just one flag and a tag. @@ -215,11 +217,43 @@ (M_PROTO1|M_PROTO2|M_PROTO3|M_PROTO4|M_PROTO5|M_PROTO6|M_PROTO7|M_PROTO8) /* + * Increasingly, network interface cards are able to hash higher-level + * protocol fields (such as IP addresses and port numbers) to identify + * possible flows that received packets may belong to. NICs use these hashes + * to maintain ordering while load balancing, as well as (in many cases) + * provide a stateless affinity model. When NICs pass up the resulting hash, + * the driver will store it in m->m_pkthdr.flowid, and set m_flag bits to + * indicate how the hash should be interpreted. + * + * Most NICs support RSS, which provides ordering and explicit affinity, and + * use the hash m_flag bits to indicate what header fields were covered by + * the hash. M_HASHTYPE_OPAQUE can be set by non-RSS cards or configurations + * that provide an opaque flow identifier, allowing for ordering and + * distribution without explicit affinity. + */ +#define M_HASHTYPE_SHIFT 24 +#define M_HASHTYPE_NONE 0x0 +#define M_HASHTYPE_RSS_IPV4 0x1 +#define M_HASHTYPE_RSS_TCP_IPV4 0x2 +#define M_HASHTYPE_RSS_IPV6 0x3 +#define M_HASHTYPE_RSS_TCP_IPV6 0x4 +#define M_HASHTYPE_RSS_IPV6_EX 0x5 +#define M_HASHTYPE_RSS_TCP_IPV6_EX 0x6 +#define M_HASHTYPE_OPAQUE 0xf + +#define M_HASHTYPE_CLEAR(m) (m)->m_flags &= ~(M_HASHTYPEBITS) +#define M_HASHTYPE_GET(m) (((m)->m_flags & M_HASHTYPEBITS) >> \ + M_HASHTYPE_SHIFT) +#define M_HASHTYPE_SET(m, v) (m)->m_flags |= (((v) << M_HASHTYPE_SHIFT) & \ + M_HASHTYPEBITS) +#define M_HASHTYPE_TEST(m, v) (M_HASHTYPE_GET(m) == (v)) + +/* * Flags preserved when copying m_pkthdr. */ #define M_COPYFLAGS \ (M_PKTHDR|M_EOR|M_RDONLY|M_PROTOFLAGS|M_SKIP_FIREWALL|M_BCAST|M_MCAST|\ - M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_VLANTAG|M_PROMISC|M_FIB) + M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_VLANTAG|M_PROMISC|M_FIB|M_HASHTYPEBITS) /* * External buffer types: identify ext_buf type.