Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/pci refactor: unify vmxnet3_start_locked and vm...



details:   https://anonhg.NetBSD.org/src/rev/5839f849c616
branches:  trunk
changeset: 842779:5839f849c616
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Wed Jul 24 10:15:23 2019 +0000

description:
refactor: unify vmxnet3_start_locked and vmxnet_transmit_locked

diffstat:

 sys/arch/x86/pci/if_vmx.c |  75 +++++++++++++++++-----------------------------
 1 files changed, 28 insertions(+), 47 deletions(-)

diffs (130 lines):

diff -r 3b425a19c33d -r 5839f849c616 sys/arch/x86/pci/if_vmx.c
--- a/sys/arch/x86/pci/if_vmx.c Wed Jul 24 10:13:14 2019 +0000
+++ b/sys/arch/x86/pci/if_vmx.c Wed Jul 24 10:15:23 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $    */
+/*     $NetBSD: if_vmx.c,v 1.39 2019/07/24 10:15:23 knakahara Exp $    */
 /*     $OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $        */
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.39 2019/07/24 10:15:23 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -2756,17 +2756,17 @@
        return (0);
 }
 
-void
-vmxnet3_start_locked(struct ifnet *ifp)
+#define VMXNET3_TX_START 1
+#define VMXNET3_TX_TRANSMIT 2
+static inline void
+vmxnet3_tx_common_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq, int txtype)
 {
        struct vmxnet3_softc *sc;
-       struct vmxnet3_txqueue *txq;
        struct vmxnet3_txring *txr;
        struct mbuf *m_head;
        int tx;
 
        sc = ifp->if_softc;
-       txq = &sc->vmx_txq[0];
        txr = &txq->vxtxq_cmd_ring;
        tx = 0;
 
@@ -2777,14 +2777,20 @@
                return;
 
        for (;;) {
-               IFQ_POLL(&ifp->if_snd, m_head);
+               if (txtype == VMXNET3_TX_START)
+                       IFQ_POLL(&ifp->if_snd, m_head);
+               else
+                       m_head = pcq_peek(txq->vxtxq_interq);
                if (m_head == NULL)
                        break;
 
                if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
                        break;
 
-               IFQ_DEQUEUE(&ifp->if_snd, m_head);
+               if (txtype == VMXNET3_TX_START)
+                       IFQ_DEQUEUE(&ifp->if_snd, m_head);
+               else
+                       m_head = pcq_get(txq->vxtxq_interq);
                if (m_head == NULL)
                        break;
 
@@ -2802,6 +2808,18 @@
                txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
 }
 
+void
+vmxnet3_start_locked(struct ifnet *ifp)
+{
+       struct vmxnet3_softc *sc;
+       struct vmxnet3_txqueue *txq;
+
+       sc = ifp->if_softc;
+       txq = &sc->vmx_txq[0];
+
+       vmxnet3_tx_common_locked(ifp, txq, VMXNET3_TX_START);
+}
+
 
 void
 vmxnet3_start(struct ifnet *ifp)
@@ -2842,45 +2860,8 @@
 void
 vmxnet3_transmit_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq)
 {
-       struct vmxnet3_softc *sc;
-       struct vmxnet3_txring *txr;
-       struct mbuf *m_head;
-       int tx;
-
-       sc = ifp->if_softc;
-       txr = &txq->vxtxq_cmd_ring;
-       tx = 0;
-
-       VMXNET3_TXQ_LOCK_ASSERT(txq);
-
-       if ((ifp->if_flags & IFF_RUNNING) == 0 ||
-           sc->vmx_link_active == 0)
-               return;
-
-       for (;;) {
-               m_head = pcq_peek(txq->vxtxq_interq);
-               if (m_head == NULL)
-                       break;
-
-               if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
-                       break;
-
-               m_head = pcq_get(txq->vxtxq_interq);
-               if (m_head == NULL)
-                       break;
-
-               if (vmxnet3_txq_encap(txq, &m_head) != 0) {
-                       if (m_head != NULL)
-                               m_freem(m_head);
-                       break;
-               }
-
-               tx++;
-               bpf_mtap(ifp, m_head, BPF_D_OUT);
-       }
-
-       if (tx > 0)
-               txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
+
+       vmxnet3_tx_common_locked(ifp, txq, VMXNET3_TX_TRANSMIT);
 }
 
 int



Home | Main Index | Thread Index | Old Index