Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic compute interrupt timer depending on bus clock.



details:   https://anonhg.NetBSD.org/src/rev/1a8f9012a9e7
branches:  trunk
changeset: 445808:1a8f9012a9e7
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Tue Nov 13 10:51:49 2018 +0000

description:
compute interrupt timer depending on bus clock.

diffstat:

 sys/dev/ic/rtl8169.c |  57 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 44 insertions(+), 13 deletions(-)

diffs (80 lines):

diff -r 3fba45494684 -r 1a8f9012a9e7 sys/dev/ic/rtl8169.c
--- a/sys/dev/ic/rtl8169.c      Tue Nov 13 10:35:32 2018 +0000
+++ b/sys/dev/ic/rtl8169.c      Tue Nov 13 10:51:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtl8169.c,v 1.154 2018/06/26 06:48:00 msaitoh Exp $    */
+/*     $NetBSD: rtl8169.c,v 1.155 2018/11/13 10:51:49 mlelstv Exp $    */
 
 /*
  * Copyright (c) 1997, 1998-2003
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtl8169.c,v 1.154 2018/06/26 06:48:00 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtl8169.c,v 1.155 2018/11/13 10:51:49 mlelstv Exp $");
 /* $FreeBSD: /repoman/r/ncvs/src/sys/dev/re/if_re.c,v 1.20 2004/04/11 20:34:08 ru Exp $ */
 
 /*
@@ -1934,19 +1934,50 @@
         * moderation, which dramatically improves TX frame rate.
         */
 
+       unsigned defer;         /* timer interval / ns */
+       unsigned period;        /* busclock period / ns */
+
+       /*
+        * Maximum frame rate
+        * 1500 byte PDU -> 81274 Hz
+        *   46 byte PDU -> 1488096 Hz
+        *
+        * Deferring interrupts by up to 128us needs descriptors for
+        * 1500 byte PDU -> 10.4 frames
+        *   46 byte PDU -> 190.4 frames
+        *
+        */
+       defer = 128000;
+
+       if ((sc->sc_quirk & RTKQ_IM_HW) == 0) {
+               period = 1;
+               defer = 0;
+       } else if ((sc->sc_quirk & RTKQ_PCIE) != 0) {
+               period = 8;
+       } else {
+               switch (CSR_READ_4(sc, RTK_CFG2_BUSFREQ) & 0x7) {
+               case RTK_BUSFREQ_33MHZ:
+                       period = 30;
+                       break;
+               case RTK_BUSFREQ_66MHZ:
+                       period = 15;
+                       break;
+               default:
+                       /* lowest possible clock */
+                       period = 60;
+                       break;
+               }
+       }
+
+       /* Timer Interrupt register address varies */
+       uint16_t re8139_reg;
        if ((sc->sc_quirk & RTKQ_8139CPLUS) != 0)
-               CSR_WRITE_4(sc, RTK_TIMERINT, 0x400);
-       else {
-               if ((sc->sc_quirk & RTKQ_IM_HW) == 0) {
-                       if ((sc->sc_quirk & RTKQ_PCIE) != 0) {
-                               CSR_WRITE_4(sc, RTK_TIMERINT_8169, 15000);
-                       } else {
-                               CSR_WRITE_4(sc, RTK_TIMERINT_8169, 0x800);
-                       }
-               } else {
-                       CSR_WRITE_4(sc, RTK_TIMERINT_8169, 0);
-               }
+               re8139_reg = RTK_TIMERINT;
+       else
+               re8139_reg = RTK_TIMERINT_8169;
+       CSR_WRITE_4(sc, re8139_reg, defer / period);
 
+       if ((sc->sc_quirk & RTKQ_8139CPLUS) == 0) {
                /*
                 * For 8169 gigE NICs, set the max allowed RX packet
                 * size so we can receive jumbo frames.



Home | Main Index | Thread Index | Old Index