Module Name: src Committed By: knakahara Date: Thu Oct 22 06:01:42 UTC 2015
Modified Files: src/sys/dev/pci: if_wm.c Log Message: initial port rss_getkey() from freebsd, and use it instead of random(). To generate a diff of this commit: cvs rdiff -u -r1.371 -r1.372 src/sys/dev/pci/if_wm.c 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.371 src/sys/dev/pci/if_wm.c:1.372 --- src/sys/dev/pci/if_wm.c:1.371 Wed Oct 14 07:16:04 2015 +++ src/sys/dev/pci/if_wm.c Thu Oct 22 06:01:41 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wm.c,v 1.371 2015/10/14 07:16:04 msaitoh Exp $ */ +/* $NetBSD: if_wm.c,v 1.372 2015/10/22 06:01:41 knakahara 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.371 2015/10/14 07:16:04 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.372 2015/10/22 06:01:41 knakahara Exp $"); #ifdef _KERNEL_OPT #include "opt_net_mpsafe.h" @@ -565,6 +565,7 @@ static uint32_t wm_rxpbs_adjust_82580(ui 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 *); #ifdef WM_MSI_MSIX static void wm_adjust_qnum(struct wm_softc *, int); @@ -4047,6 +4048,42 @@ 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. * @@ -4055,7 +4092,7 @@ wm_rxdrain(struct wm_rxqueue *rxq) static void wm_init_rss(struct wm_softc *sc) { - uint32_t mrqc, reta_reg; + uint32_t mrqc, reta_reg, rss_key[RSSRK_NUM_REGS]; int i; for (i = 0; i < RETA_NUM_ENTRIES; i++) { @@ -4082,8 +4119,9 @@ wm_init_rss(struct wm_softc *sc) CSR_WRITE(sc, WMREG_RETA_Q(i), reta_reg); } + wm_rss_getkey((uint8_t *)rss_key); for (i = 0; i < RSSRK_NUM_REGS; i++) - CSR_WRITE(sc, WMREG_RSSRK(i), (uint32_t)random()); + CSR_WRITE(sc, WMREG_RSSRK(i), rss_key[i]); if (sc->sc_type == WM_T_82574) mrqc = MRQC_ENABLE_RSS_MQ_82574;