Add RX interrupt moderation suport for PCI-E GigaE chips.
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 6 Oct 2008 14:22:32 +0000 (14:22 +0000)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 6 Oct 2008 14:22:32 +0000 (14:22 +0000)
Interrupt moderation register position is obtained from Realtek's
BSD driver v176.
The meaning of the IM register bits is partially reverse engineered:
RX timer position and unit.

This kind of interrupt moderation does not work on PCI GigaE chips.

sys/dev/netif/re/if_re.c
sys/dev/netif/re/if_rereg.h
sys/dev/netif/re/if_revar.h

index 61124b0..61f0ab7 100644 (file)
@@ -33,7 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/re/if_re.c,v 1.25 2004/06/09 14:34:01 naddy Exp $
- * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.67 2008/10/05 08:28:32 sephe Exp $
+ * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.68 2008/10/06 14:22:32 sephe Exp $
  */
 
 /*
@@ -205,16 +205,16 @@ static const struct re_hwrev re_hwrevs[] = {
        { RE_HWREV_8139CPLUS,   RE_8139CPLUS,   RE_F_HASMPC,
          ETHERMTU, ETHERMTU },
 
-       { RE_HWREV_8168_SPIN1,  RE_8169,        RE_F_PCIE,
+       { RE_HWREV_8168_SPIN1,  RE_8169,        RE_F_PCIE | RE_F_HASIM,
          RE_JUMBO_MTU, RE_JUMBO_MTU },
 
-       { RE_HWREV_8168_SPIN2,  RE_8169,        RE_F_PCIE,
+       { RE_HWREV_8168_SPIN2,  RE_8169,        RE_F_PCIE | RE_F_HASIM,
          RE_JUMBO_MTU, RE_JUMBO_MTU },
 
-       { RE_HWREV_8168_SPIN3,  RE_8169,        RE_F_PCIE,
+       { RE_HWREV_8168_SPIN3,  RE_8169,        RE_F_PCIE | RE_F_HASIM,
          RE_JUMBO_MTU, RE_JUMBO_MTU },
 
-       { RE_HWREV_8168C,       RE_8169,        RE_F_PCIE,
+       { RE_HWREV_8168C,       RE_8169,        RE_F_PCIE | RE_F_HASIM,
          RE_JUMBO_MTU, RE_JUMBO_MTU },
 
        { RE_HWREV_8169,        RE_8169,        RE_F_HASMPC,
@@ -2389,6 +2389,36 @@ re_init(void *xsc)
                    (ifp->if_capenable & IFCAP_RXCSUM ?
                     RE_CPLUSCMD_RXCSUM_ENB : 0));
 
+       if (sc->re_flags & RE_F_HASIM) {
+               /*
+                * Interrupt moderation
+                *
+                * 0xUUuD
+                * U - unknown (maybe TX related)
+                * u - unknown (maybe RX related)
+                * D - RX timer (unit: 25us)
+                *
+                * Set RX timer to 125us
+                * TODO: sysctl variable
+                *
+                *
+                * re(4)'s interrupt moderation is actually controlled by
+                * two variables, like most other NICs (bge, bce etc.)
+                * o  timer
+                * o  number of packets [P]
+                *
+                * The logic relationship between these two variables is
+                * similar to other NICs too:
+                * if (timer expire || packets > [P])
+                *     Interrupt is delivered
+                *
+                * Currently we only know how to set 'timer', but not
+                * 'number of packets', which should be ~30, as far as I
+                * tested (sink ~900Kpps, interrupt rate is 30KHz)
+                */
+               CSR_WRITE_2(sc, RE_IM, 0x5155);
+       }
+
        /*
         * Init our MAC address.  Even though the chipset
         * documentation doesn't mention it, we need to enter "Config
index c766891..3b136d8 100644 (file)
@@ -33,7 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/pci/if_rlreg.h,v 1.42 2004/05/24 19:39:23 jhb Exp $
- * $DragonFly: src/sys/dev/netif/re/if_rereg.h,v 1.13 2008/10/05 06:15:36 sephe Exp $
+ * $DragonFly: src/sys/dev/netif/re/if_rereg.h,v 1.14 2008/10/06 14:22:32 sephe Exp $
  */
 
 /*
 #define RE_TIMERINT            0x0054  /* interrupt on timer expire */
 #define RE_TXSTART             0x00D9  /* 8 bits */
 #define RE_CPLUS_CMD           0x00E0  /* 16 bits */
+#define RE_IM                  0x00E2  /* 16 bits */
 #define RE_RXLIST_ADDR_LO      0x00E4  /* 64 bits, 256 byte alignment */
 #define RE_RXLIST_ADDR_HI      0x00E8  /* 64 bits, 256 byte alignment */
 #define RE_EARLY_TX_THRESH     0x00EC  /* 8 bits */
index 7b982e3..a03aecb 100644 (file)
@@ -33,7 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/pci/if_rlreg.h,v 1.42 2004/05/24 19:39:23 jhb Exp $
- * $DragonFly: src/sys/dev/netif/re/if_revar.h,v 1.13 2008/10/05 06:15:36 sephe Exp $
+ * $DragonFly: src/sys/dev/netif/re/if_revar.h,v 1.14 2008/10/06 14:22:32 sephe Exp $
  */
 
 #define RE_RX_DESC_CNT_DEF     64
@@ -170,6 +170,7 @@ struct re_softc {
 #define RE_F_HASMPC            0x1
 #define RE_F_PCIE              0x2
 #define RE_F_PCI64             0x4
+#define RE_F_HASIM             0x8
 
 #define RE_TX_MODERATION_IS_ENABLED(sc)                        \
        ((sc)->re_tx_ack == RE_ISR_TIMEOUT_EXPIRED)