Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src/sys/dev/pci Pull up following revision(s) (requested by m...



details:   https://anonhg.NetBSD.org/src/rev/c83c0dbb3b73
branches:  netbsd-8
changeset: 852464:c83c0dbb3b73
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Aug 01 13:50:13 2019 +0000

description:
Pull up following revision(s) (requested by msaitoh in ticket #1312):

        sys/dev/pci/if_wm.c: revision 1.644
        sys/dev/pci/if_wm.c: revision 1.645
        sys/dev/pci/if_wmreg.h: revision 1.115

 Define RETA_ENTRY_MASK_Q(used in RSS redirection table) correctly.
Found by UBSan.

 Use aprint_debug_dev() instead of printf() in wm_ulp_disable().

- rnd_add_*() call must be serialized. Unserialized accesses broke the
  sc->rnd_source structure and caused off by one in kern_rndq.c's
  rnd_add_data_ts(). This problem was found by kUBSan. Make krndsource_t's
  data per queue-pair and call rnd_add_uint32() in wm_txrxintr_msix(). One of
  the reason why rnd_add_uint32() calls were moved from wm_{tx,rx}eof() is that
  rnd(9) manual page says "To allow the system to gather the timing information
  accurately, this call should be placed within the actual hardware interrupt
  service routine."

- Pass a better value to rnd_add_uint32() in wm_intr_legacy().
XXX pullup-8.

diffstat:

 sys/dev/pci/if_wm.c    |  53 +++++++++++++++++++++++++++++++++----------------
 sys/dev/pci/if_wmreg.h |   4 +-
 2 files changed, 38 insertions(+), 19 deletions(-)

diffs (201 lines):

diff -r ac50298563e5 -r c83c0dbb3b73 sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Thu Aug 01 13:45:55 2019 +0000
+++ b/sys/dev/pci/if_wm.c       Thu Aug 01 13:50:13 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wm.c,v 1.508.4.33 2019/07/17 16:12:17 martin Exp $  */
+/*     $NetBSD: if_wm.c,v 1.508.4.34 2019/08/01 13:50:13 martin Exp $  */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.33 2019/07/17 16:12:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.34 2019/08/01 13:50:13 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -233,7 +233,7 @@
  * packet.  We allocate 256 receive descriptors, each with a 2k
  * buffer (MCLBYTES), which gives us room for 50 jumbo packets.
  */
-#define        WM_NRXDESC              256
+#define        WM_NRXDESC              256U
 #define        WM_NRXDESC_MASK         (WM_NRXDESC - 1)
 #define        WM_NEXTRX(x)            (((x) + 1) & WM_NRXDESC_MASK)
 #define        WM_PREVRX(x)            (((x) - 1) & WM_NRXDESC_MASK)
@@ -457,6 +457,7 @@
        struct wm_rxqueue wmq_rxq;
 
        void *wmq_si;
+       krndsource_t rnd_source;        /* random source */
 };
 
 struct wm_phyop {
@@ -584,8 +585,6 @@
 
        int sc_mchash_type;             /* multicast filter offset */
 
-       krndsource_t rnd_source;        /* random source */
-
        struct if_percpuq *sc_ipq;      /* softint-based input queues */
 
        kmutex_t *sc_core_lock;         /* lock for softc operations */
@@ -2930,8 +2929,6 @@
        ether_ifattach(ifp, enaddr);
        ether_set_ifflags_cb(&sc->sc_ethercom, wm_ifflags_cb);
        if_register(ifp);
-       rnd_attach_source(&sc->rnd_source, xname, RND_TYPE_NET,
-           RND_FLAG_DEFAULT);
 
 #ifdef WM_EVENT_COUNTERS
        /* Attach event counters. */
@@ -2986,8 +2983,6 @@
        evcnt_detach(&sc->sc_ev_rx_macctl);
 #endif /* WM_EVENT_COUNTERS */
 
-       rnd_detach_source(&sc->rnd_source);
-
        /* Tell the firmware about the release */
        WM_CORE_LOCK(sc);
        wm_release_manageability(sc);
@@ -6763,6 +6758,15 @@
        if (error)
                goto fail_2;
 
+       for (i = 0; i < sc->sc_nqueues; i++) {
+               char rndname[16];
+
+               snprintf(rndname, sizeof(rndname), "%sTXRX%d",
+                   device_xname(sc->sc_dev), i);
+               rnd_attach_source(&sc->sc_queue[i].rnd_source, rndname,
+                   RND_TYPE_NET, RND_FLAG_DEFAULT);
+       }
+
        return 0;
 
  fail_2:
@@ -6798,6 +6802,9 @@
 {
        int i;
 
+       for (i = 0; i < sc->sc_nqueues; i++)
+               rnd_detach_source(&sc->sc_queue[i].rnd_source);
+
        for (i = 0; i < sc->sc_nqueues; i++) {
                struct wm_rxqueue *rxq = &sc->sc_queue[i].wmq_rxq;
 
@@ -8464,9 +8471,6 @@
        DPRINTF(WM_DEBUG_TX,
            ("%s: TX: txsdirty -> %d\n", device_xname(sc->sc_dev), i));
 
-       if (count != 0)
-               rnd_add_uint32(&sc->rnd_source, count);
-
        /*
         * If there are no more pending transmissions, cancel the watchdog
         * timer.
@@ -8880,9 +8884,6 @@
                        break;
        }
 
-       if (count != 0)
-               rnd_add_uint32(&sc->rnd_source, count);
-
        DPRINTF(WM_DEBUG_RX,
            ("%s: RX: rxptr -> %d\n", device_xname(sc->sc_dev), i));
 
@@ -9228,6 +9229,8 @@
                 * So, we can call wm_rxeof() in interrupt context.
                 */
                wm_rxeof(rxq, UINT_MAX);
+               /* Fill lower bits with RX index. See below for the upper. */
+               rndval |= rxq->rxq_ptr & WM_NRXDESC_MASK;
 
                mutex_exit(rxq->rxq_lock);
                mutex_enter(txq->txq_lock);
@@ -9246,6 +9249,8 @@
                }
 #endif
                wm_txeof(txq, UINT_MAX);
+               /* Fill upper bits with TX index. See above for the lower. */
+               rndval = txq->txq_next * WM_NRXDESC;
 
                mutex_exit(txq->txq_lock);
                WM_CORE_LOCK(sc);
@@ -9270,7 +9275,7 @@
                }
        }
 
-       rnd_add_uint32(&sc->rnd_source, rndval);
+       rnd_add_uint32(&sc->sc_queue[0].rnd_source, rndval);
 
        if (handled) {
                /* Try to get more packets going. */
@@ -9327,6 +9332,7 @@
        struct wm_softc *sc = txq->txq_sc;
        u_int txlimit = sc->sc_tx_intr_process_limit;
        u_int rxlimit = sc->sc_rx_intr_process_limit;
+       uint32_t rndval = 0;
        bool txmore;
        bool rxmore;
 
@@ -9346,6 +9352,8 @@
 
        WM_Q_EVCNT_INCR(txq, txdw);
        txmore = wm_txeof(txq, txlimit);
+       /* Fill upper bits with TX index. See below for the lower. */
+       rndval = txq->txq_next * WM_NRXDESC;
        /* wm_deferred start() is done in wm_handle_queue(). */
        mutex_exit(txq->txq_lock);
 
@@ -9360,10 +9368,20 @@
 
        WM_Q_EVCNT_INCR(rxq, intr);
        rxmore = wm_rxeof(rxq, rxlimit);
+
+       /* Fill lower bits with RX index. See above for the upper. */
+       rndval |= rxq->rxq_ptr & WM_NRXDESC_MASK;
        mutex_exit(rxq->rxq_lock);
 
        wm_itrs_writereg(sc, wmq);
 
+       /*
+        * This function is called in the hardware interrupt context and
+        * per-CPU, so it's not required to take a lock.
+        */
+       if (rndval != 0)
+               rnd_add_uint32(&sc->sc_queue[wmq->wmq_id].rnd_source, rndval);
+
        if (txmore || rxmore)
                softint_schedule(wmq->wmq_si);
        else
@@ -14344,7 +14362,8 @@
        if (rv != 0) {
                uint32_t reg2;
 
-               printf("%s: Force SMBus first.\n", __func__);
+               aprint_debug_dev(sc->sc_dev, "%s: Force SMBus first.\n",
+                       __func__);
                reg2 = CSR_READ(sc, WMREG_CTRL_EXT);
                reg2 |= CTRL_EXT_FORCE_SMBUS;
                CSR_WRITE(sc, WMREG_CTRL_EXT, reg2);
diff -r ac50298563e5 -r c83c0dbb3b73 sys/dev/pci/if_wmreg.h
--- a/sys/dev/pci/if_wmreg.h    Thu Aug 01 13:45:55 2019 +0000
+++ b/sys/dev/pci/if_wmreg.h    Thu Aug 01 13:50:13 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wmreg.h,v 1.98.6.9 2019/07/17 16:12:17 martin Exp $ */
+/*     $NetBSD: if_wmreg.h,v 1.98.6.10 2019/08/01 13:50:14 martin Exp $        */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -1269,7 +1269,7 @@
 
 #define WMREG_RETA_Q(x)                (0x5c00 + ((x) >> 2) * 4) /* Redirection Table */
 #define RETA_NUM_ENTRIES       128
-#define RETA_ENTRY_MASK_Q(x)   (0x000000ff << (((x) % 4) * 8)) /* Redirection Table */
+#define RETA_ENTRY_MASK_Q(x)   (0x000000ffUL << (((x) % 4) * 8)) /* Redirection Table */
 #define RETA_ENT_QINDEX_MASK           __BITS(3,0) /*queue index for 82580 and newer */
 #define RETA_ENT_QINDEX0_MASK_82575    __BITS(3,2) /*queue index for pool0 */
 #define RETA_ENT_QINDEX1_MASK_82575    __BITS(7,6) /*queue index for pool1 and regular RSS */



Home | Main Index | Thread Index | Old Index