Module Name: src Committed By: snj Date: Mon Feb 26 00:25:16 UTC 2018
Modified Files: src/sys/dev/pci [netbsd-8]: if_wm.c src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe_rss.h ixv.c src/sys/net [netbsd-8]: files.net Added Files: src/sys/net [netbsd-8]: rss_config.c rss_config.h Log Message: Pull up following revision(s) (requested by knakahara in ticket #567): distrib/sets/lists/comp/mi: 1.2182-1.2183 sys/dev/pci/if_wm.c: 1.564 sys/dev/pci/ixgbe/ixgbe.c: 1.122 sys/dev/pci/ixgbe/ixgbe_rss.h: 1.3 sys/dev/pci/ixgbe/ixv.c: 1.78 sys/net/Makefile: 1.35-1.36 sys/net/files.net: 1.15 sys/net/rss_config.c: 1.1 sys/net/rss_config.h: 1.1 Introduce very simple Receive Side Scaling (RSS) utility. ok by msaitoh@n.o. -- Apply RSS utility to wm(4). ok by msaitoh@n.o. -- Apply RSS utility to ixg(4) and ixv(4). ok by msaitoh@n.o. -- Fix build failure, sorry. -- Currently, it is not necessary to install rss_config.h. Pointed out by msaitoh@n.o. To generate a diff of this commit: cvs rdiff -u -r1.508.4.14 -r1.508.4.15 src/sys/dev/pci/if_wm.c cvs rdiff -u -r1.88.2.8 -r1.88.2.9 src/sys/dev/pci/ixgbe/ixgbe.c cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/pci/ixgbe/ixgbe_rss.h cvs rdiff -u -r1.56.2.5 -r1.56.2.6 src/sys/dev/pci/ixgbe/ixv.c cvs rdiff -u -r1.13.6.1 -r1.13.6.2 src/sys/net/files.net cvs rdiff -u -r0 -r1.1.2.2 src/sys/net/rss_config.c src/sys/net/rss_config.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/if_wm.c diff -u src/sys/dev/pci/if_wm.c:1.508.4.14 src/sys/dev/pci/if_wm.c:1.508.4.15 --- src/sys/dev/pci/if_wm.c:1.508.4.14 Mon Feb 26 00:00:53 2018 +++ src/sys/dev/pci/if_wm.c Mon Feb 26 00:25:16 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wm.c,v 1.508.4.14 2018/02/26 00:00:53 snj Exp $ */ +/* $NetBSD: if_wm.c,v 1.508.4.15 2018/02/26 00:25:16 snj Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. @@ -83,7 +83,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.14 2018/02/26 00:00:53 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.15 2018/02/26 00:25:16 snj Exp $"); #ifdef _KERNEL_OPT #include "opt_net_mpsafe.h" @@ -116,6 +116,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1. #include <net/bpf.h> +#include <net/rss_config.h> + #include <netinet/in.h> /* XXX for struct ip */ #include <netinet/in_systm.h> /* XXX for struct ip */ #include <netinet/ip.h> /* XXX for struct ip */ @@ -715,7 +717,6 @@ static void wm_flush_desc_rings(struct w static void wm_reset(struct wm_softc *); static int wm_add_rxbuf(struct wm_rxqueue *, int); static void wm_rxdrain(struct wm_rxqueue *); -static void wm_rss_getkey(uint8_t *); static void wm_init_rss(struct wm_softc *); static void wm_adjust_qnum(struct wm_softc *, int); static inline bool wm_is_using_msix(struct wm_softc *); @@ -4838,43 +4839,6 @@ wm_rxdrain(struct wm_rxqueue *rxq) } } - -/* - * XXX copy from FreeBSD's sys/net/rss_config.c - */ -/* - * RSS secret key, intended to prevent attacks on load-balancing. Its - * effectiveness may be limited by algorithm choice and available entropy - * during the boot. - * - * XXXRW: And that we don't randomize it yet! - * - * This is the default Microsoft RSS specification key which is also - * the Chelsio T5 firmware default key. - */ -#define RSS_KEYSIZE 40 -static uint8_t wm_rss_key[RSS_KEYSIZE] = { - 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, - 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, - 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, - 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, - 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, -}; - -/* - * Caller must pass an array of size sizeof(rss_key). - * - * XXX - * As if_ixgbe may use this function, this function should not be - * if_wm specific function. - */ -static void -wm_rss_getkey(uint8_t *key) -{ - - memcpy(key, wm_rss_key, sizeof(wm_rss_key)); -} - /* * Setup registers for RSS. * @@ -4886,7 +4850,7 @@ wm_init_rss(struct wm_softc *sc) uint32_t mrqc, reta_reg, rss_key[RSSRK_NUM_REGS]; int i; - CTASSERT(sizeof(rss_key) == sizeof(wm_rss_key)); + CTASSERT(sizeof(rss_key) == RSS_KEYSIZE); for (i = 0; i < RETA_NUM_ENTRIES; i++) { int qid, reta_ent; @@ -4912,7 +4876,7 @@ wm_init_rss(struct wm_softc *sc) CSR_WRITE(sc, WMREG_RETA_Q(i), reta_reg); } - wm_rss_getkey((uint8_t *)rss_key); + rss_getkey((uint8_t *)rss_key); for (i = 0; i < RSSRK_NUM_REGS; i++) CSR_WRITE(sc, WMREG_RSSRK(i), rss_key[i]); Index: src/sys/dev/pci/ixgbe/ixgbe.c diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.8 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.9 --- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.8 Sat Jan 13 21:40:01 2018 +++ src/sys/dev/pci/ixgbe/ixgbe.c Mon Feb 26 00:25:16 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ixgbe.c,v 1.88.2.8 2018/01/13 21:40:01 snj Exp $ */ +/* $NetBSD: ixgbe.c,v 1.88.2.9 2018/02/26 00:25:16 snj Exp $ */ /****************************************************************************** @@ -411,6 +411,10 @@ ixgbe_initialize_rss_mapping(struct adap int i, j; u32 rss_hash_config; + /* force use default RSS key. */ +#ifdef __NetBSD__ + rss_getkey((uint8_t *) &rss_key); +#else if (adapter->feat_en & IXGBE_FEATURE_RSS) { /* Fetch the configured RSS key */ rss_getkey((uint8_t *) &rss_key); @@ -418,6 +422,7 @@ ixgbe_initialize_rss_mapping(struct adap /* set up random bits */ cprng_fast(&rss_key, sizeof(rss_key)); } +#endif /* Set multiplier for RETA setup and table size based on MAC */ index_mult = 0x1; Index: src/sys/dev/pci/ixgbe/ixgbe_rss.h diff -u src/sys/dev/pci/ixgbe/ixgbe_rss.h:1.2.2.2 src/sys/dev/pci/ixgbe/ixgbe_rss.h:1.2.2.3 --- src/sys/dev/pci/ixgbe/ixgbe_rss.h:1.2.2.2 Thu Dec 21 19:28:54 2017 +++ src/sys/dev/pci/ixgbe/ixgbe_rss.h Mon Feb 26 00:25:16 2018 @@ -35,6 +35,26 @@ #ifndef _IXGBE_RSS_H_ #define _IXGBE_RSS_H_ +#ifdef __NetBSD__ +#include <net/rss_config.h> + +#define RSS_HASHTYPE_RSS_IPV4 (1 << 1) +#define RSS_HASHTYPE_RSS_TCP_IPV4 (1 << 2) +#define RSS_HASHTYPE_RSS_IPV6 (1 << 3) +#define RSS_HASHTYPE_RSS_TCP_IPV6 (1 << 4) +#define RSS_HASHTYPE_RSS_IPV6_EX (1 << 5) +#define RSS_HASHTYPE_RSS_TCP_IPV6_EX (1 << 6) +#define RSS_HASHTYPE_RSS_UDP_IPV4 (1 << 7) +#define RSS_HASHTYPE_RSS_UDP_IPV6 (1 << 9) +#define RSS_HASHTYPE_RSS_UDP_IPV6_EX (1 << 10) + +#define rss_getcpu(_a) 0 +#define rss_getnumbuckets() 1 +#define rss_get_indirection_to_bucket(_a) 0 +#define rss_gethashconfig() 0x7E +#define rss_hash2bucket(_a,_b,_c) -1 + +#else #ifdef RSS #include <net/rss_config.h> @@ -60,4 +80,5 @@ #define rss_hash2bucket(_a,_b,_c) -1 #endif +#endif /* __NetBSD__ */ #endif /* _IXGBE_RSS_H_ */ Index: src/sys/dev/pci/ixgbe/ixv.c diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56.2.5 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.6 --- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.5 Sat Jan 13 21:40:01 2018 +++ src/sys/dev/pci/ixgbe/ixv.c Mon Feb 26 00:25:16 2018 @@ -1,4 +1,4 @@ -/*$NetBSD: ixv.c,v 1.56.2.5 2018/01/13 21:40:01 snj Exp $*/ +/*$NetBSD: ixv.c,v 1.56.2.6 2018/02/26 00:25:16 snj Exp $*/ /****************************************************************************** @@ -1527,6 +1527,10 @@ ixv_initialize_rss_mapping(struct adapte int i, j; u32 rss_hash_config; + /* force use default RSS key. */ +#ifdef __NetBSD__ + rss_getkey((uint8_t *) &rss_key); +#else if (adapter->feat_en & IXGBE_FEATURE_RSS) { /* Fetch the configured RSS key */ rss_getkey((uint8_t *)&rss_key); @@ -1534,6 +1538,7 @@ ixv_initialize_rss_mapping(struct adapte /* set up random bits */ cprng_fast(&rss_key, sizeof(rss_key)); } +#endif /* Now fill out hash function seeds */ for (i = 0; i < 10; i++) Index: src/sys/net/files.net diff -u src/sys/net/files.net:1.13.6.1 src/sys/net/files.net:1.13.6.2 --- src/sys/net/files.net:1.13.6.1 Sun Feb 11 21:17:34 2018 +++ src/sys/net/files.net Mon Feb 26 00:25:16 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.net,v 1.13.6.1 2018/02/11 21:17:34 snj Exp $ +# $NetBSD: files.net,v 1.13.6.2 2018/02/26 00:25:16 snj Exp $ # XXX CLEANUP define net @@ -48,6 +48,7 @@ file net/radix.c net file net/raw_cb.c net file net/raw_usrreq.c net file net/route.c net +file net/rss_config.c net file net/rtbl.c net file net/rtsock.c net file net/slcompress.c sl | ppp | strip | (irip & irip_vj) Added files: Index: src/sys/net/rss_config.c diff -u /dev/null src/sys/net/rss_config.c:1.1.2.2 --- /dev/null Mon Feb 26 00:25:16 2018 +++ src/sys/net/rss_config.c Mon Feb 26 00:25:16 2018 @@ -0,0 +1,76 @@ +/* $NetBSD: rss_config.c,v 1.1.2.2 2018/02/26 00:25:16 snj Exp $ */ + +/* + * Copyright (c) 2018 Internet Initiative Japan Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.1.2.2 2018/02/26 00:25:16 snj Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> + +#include <net/rss_config.h> + +/* + * Same as FreeBSD. + * + * This rss key is assumed for verification suite in many intel Gigabit and + * 10 Gigabit Controller specifications. + */ +static uint8_t rss_default_key[RSS_KEYSIZE] = { + 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, + 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, + 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, + 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, + 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +}; + +#ifdef NOTYET +/* + * Same as DragonFlyBSD. + * + * This rss key make rss hash value symmetric, that is, the hash value + * calculated by func("source address", "destination address") equals to + * the hash value calculated by func("destination address", "source address"). + */ +static uint8_t rss_symmetric_key[RSS_KEYSIZE] = { + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, +}; +#endif + +/* + * sizeof(key) must be more than or equal to RSS_KEYSIZE. + */ +void +rss_getkey(uint8_t *key) +{ + + memcpy(key, rss_default_key, sizeof(rss_default_key)); +} Index: src/sys/net/rss_config.h diff -u /dev/null src/sys/net/rss_config.h:1.1.2.2 --- /dev/null Mon Feb 26 00:25:16 2018 +++ src/sys/net/rss_config.h Mon Feb 26 00:25:16 2018 @@ -0,0 +1,36 @@ +/* $NetBSD: rss_config.h,v 1.1.2.2 2018/02/26 00:25:16 snj Exp $ */ + +/* + * Copyright (c) 2018 Internet Initiative Japan Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NET_RSS_CONFIG_H_ +#define _NET_RSS_CONFIG_H_ + +#define RSS_KEYSIZE 40 + +void rss_getkey(uint8_t *); + +#endif /* _NET_RSS_CONFIG_H_ */