Source-Changes-HG archive

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

[src/trunk]: src/sys/net/agr Simplify; share agr_vlan_add and agr_vlan_del (N...



details:   https://anonhg.NetBSD.org/src/rev/f7a02242cc21
branches:  trunk
changeset: 828261:f7a02242cc21
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Dec 06 04:37:00 2017 +0000

description:
Simplify; share agr_vlan_add and agr_vlan_del (NFCI)

diffstat:

 sys/net/agr/if_agr.c      |  63 ++-----------------------------------------
 sys/net/agr/if_agrether.c |  36 +++++-------------------
 sys/net/agr/if_agrsubr.c  |  67 +++++++++++++++++++++++++++++++++++++++++++++-
 sys/net/agr/if_agrsubr.h  |   5 ++-
 4 files changed, 81 insertions(+), 90 deletions(-)

diffs (266 lines):

diff -r 27c34f1f6c43 -r f7a02242cc21 sys/net/agr/if_agr.c
--- a/sys/net/agr/if_agr.c      Wed Dec 06 04:29:58 2017 +0000
+++ b/sys/net/agr/if_agr.c      Wed Dec 06 04:37:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_agr.c,v 1.41 2017/01/28 22:56:09 maya Exp $ */
+/*     $NetBSD: if_agr.c,v 1.42 2017/12/06 04:37:00 ozaki-r Exp $      */
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.41 2017/01/28 22:56:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.42 2017/12/06 04:37:00 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -254,62 +254,6 @@
 /*
  * INTERNAL FUNCTIONS
  */
-
-/*
- * Enable vlan hardware assist for the specified port.
- */
-static int
-agr_vlan_add(struct agr_port *port, void *arg)
-{
-       struct ifnet *ifp = port->port_ifp;
-       struct ethercom *ec_port = (void *)ifp;
-       int error=0;
-
-       if (ec_port->ec_nvlans++ == 0 &&
-           (ec_port->ec_capabilities & ETHERCAP_VLAN_MTU) != 0) {
-               struct ifnet *p = port->port_ifp;
-               /*
-                * Enable Tx/Rx of VLAN-sized frames.
-                */
-               ec_port->ec_capenable |= ETHERCAP_VLAN_MTU;
-               if (p->if_flags & IFF_UP) {
-                       error = if_flags_set(p, p->if_flags);
-                       if (error) {
-                               if (ec_port->ec_nvlans-- == 1)
-                                       ec_port->ec_capenable &=
-                                           ~ETHERCAP_VLAN_MTU;
-                               return (error);
-                       }
-               }
-       }
-
-       return error;
-}
-
-/*
- * Disable vlan hardware assist for the specified port.
- */
-static int
-agr_vlan_del(struct agr_port *port, void *arg)
-{
-       struct ethercom *ec_port = (void *)port->port_ifp;
-
-       /* Disable vlan support */
-       if (ec_port->ec_nvlans-- == 1) {
-               /*
-                * Disable Tx/Rx of VLAN-sized frames.
-                */
-               ec_port->ec_capenable &= ~ETHERCAP_VLAN_MTU;
-               if (port->port_ifp->if_flags & IFF_UP) {
-                       (void)if_flags_set(port->port_ifp,
-                           port->port_ifp->if_flags);
-               }
-       }
-
-       return 0;
-}
-
-
 /*
  * Check for vlan attach/detach.
  * ec->ec_nvlans is directly modified by the vlan driver.
@@ -332,8 +276,9 @@
                agr_port_foreach(sc, agr_vlan_add, NULL);
                sc->sc_nvlans = ec->ec_nvlans;
        } else if (ec->ec_nvlans == 0) {
+               bool force_zero = false;
                /* vlan removed */
-               agr_port_foreach(sc, agr_vlan_del, NULL);
+               agr_port_foreach(sc, agr_vlan_del, &force_zero);
                sc->sc_nvlans = 0;
        }
 }
diff -r 27c34f1f6c43 -r f7a02242cc21 sys/net/agr/if_agrether.c
--- a/sys/net/agr/if_agrether.c Wed Dec 06 04:29:58 2017 +0000
+++ b/sys/net/agr/if_agrether.c Wed Dec 06 04:37:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_agrether.c,v 1.9 2011/10/19 01:49:50 dyoung Exp $   */
+/*     $NetBSD: if_agrether.c,v 1.10 2017/12/06 04:37:00 ozaki-r Exp $ */
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agrether.c,v 1.9 2011/10/19 01:49:50 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agrether.c,v 1.10 2017/12/06 04:37:00 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -166,23 +166,10 @@
        }
 
        /* Enable vlan support */
-       if ((ec->ec_nvlans > 0) && 
-            ec_port->ec_nvlans++ == 0 &&
-           (ec_port->ec_capabilities & ETHERCAP_VLAN_MTU) != 0) {
-               struct ifnet *p = port->port_ifp;
-               /*
-                * Enable Tx/Rx of VLAN-sized frames.
-                */
-               ec_port->ec_capenable |= ETHERCAP_VLAN_MTU;
-               if (p->if_flags & IFF_UP) {
-                       error = if_flags_set(p, p->if_flags);
-                       if (error) {
-                               if (ec_port->ec_nvlans-- == 1)
-                                       ec_port->ec_capenable &=
-                                           ~ETHERCAP_VLAN_MTU;
-                               return (error);
-                       }
-               }
+       if (ec->ec_nvlans > 0) {
+               error = agr_vlan_add(port, NULL);
+               if (error != 0)
+                       return error;
        }
        /* XXX ETHERCAP_JUMBO_MTU */
 
@@ -225,16 +212,9 @@
        }
 
        if (ec_port->ec_nvlans > 0) {
+               bool force = true;
                /* Disable vlan support */
-               ec_port->ec_nvlans = 0;
-               /*
-                * Disable Tx/Rx of VLAN-sized frames.
-                */
-               ec_port->ec_capenable &= ~ETHERCAP_VLAN_MTU;
-               if (port->port_ifp->if_flags & IFF_UP) {
-                       (void)if_flags_set(port->port_ifp,
-                           port->port_ifp->if_flags);
-               }
+               agr_vlan_del(port, &force);
        }
 
        memset(&ifr, 0, sizeof(ifr));
diff -r 27c34f1f6c43 -r f7a02242cc21 sys/net/agr/if_agrsubr.c
--- a/sys/net/agr/if_agrsubr.c  Wed Dec 06 04:29:58 2017 +0000
+++ b/sys/net/agr/if_agrsubr.c  Wed Dec 06 04:37:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_agrsubr.c,v 1.10 2015/08/24 22:21:26 pooka Exp $    */
+/*     $NetBSD: if_agrsubr.c,v 1.11 2017/12/06 04:37:00 ozaki-r Exp $  */
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agrsubr.c,v 1.10 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agrsubr.c,v 1.11 2017/12/06 04:37:00 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -42,6 +42,7 @@
 #include <sys/sockio.h>
 
 #include <net/if.h>
+#include <net/if_ether.h>
 
 #include <net/agr/if_agrvar_impl.h>
 #include <net/agr/if_agrsubr.h>
@@ -272,3 +273,65 @@
 
        return error;
 }
+
+/* ==================== */
+
+/*
+ * Enable vlan hardware assist for the specified port.
+ */
+int
+agr_vlan_add(struct agr_port *port, void *arg)
+{
+       struct ifnet *ifp = port->port_ifp;
+       struct ethercom *ec_port = (void *)ifp;
+       int error=0;
+
+       if (ec_port->ec_nvlans++ == 0 &&
+           (ec_port->ec_capabilities & ETHERCAP_VLAN_MTU) != 0) {
+               struct ifnet *p = port->port_ifp;
+               /*
+                * Enable Tx/Rx of VLAN-sized frames.
+                */
+               ec_port->ec_capenable |= ETHERCAP_VLAN_MTU;
+               if (p->if_flags & IFF_UP) {
+                       error = if_flags_set(p, p->if_flags);
+                       if (error) {
+                               if (ec_port->ec_nvlans-- == 1)
+                                       ec_port->ec_capenable &=
+                                           ~ETHERCAP_VLAN_MTU;
+                               return (error);
+                       }
+               }
+       }
+
+       return error;
+}
+
+/*
+ * Disable vlan hardware assist for the specified port.
+ */
+int
+agr_vlan_del(struct agr_port *port, void *arg)
+{
+       struct ethercom *ec_port = (void *)port->port_ifp;
+       bool *force_zero = (bool *)arg;
+
+       KASSERT(force_zero != NULL);
+
+       /* Disable vlan support */
+       if ((*force_zero && ec_port->ec_nvlans > 0) ||
+           ec_port->ec_nvlans-- == 1) {
+               if (*force_zero)
+                       ec_port->ec_nvlans = 0;
+               /*
+                * Disable Tx/Rx of VLAN-sized frames.
+                */
+               ec_port->ec_capenable &= ~ETHERCAP_VLAN_MTU;
+               if (port->port_ifp->if_flags & IFF_UP) {
+                       (void)if_flags_set(port->port_ifp,
+                           port->port_ifp->if_flags);
+               }
+       }
+
+       return 0;
+}
diff -r 27c34f1f6c43 -r f7a02242cc21 sys/net/agr/if_agrsubr.h
--- a/sys/net/agr/if_agrsubr.h  Wed Dec 06 04:29:58 2017 +0000
+++ b/sys/net/agr/if_agrsubr.h  Wed Dec 06 04:37:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_agrsubr.h,v 1.4 2007/02/21 23:00:07 thorpej Exp $   */
+/*     $NetBSD: if_agrsubr.h,v 1.5 2017/12/06 04:37:00 ozaki-r Exp $   */
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -51,4 +51,7 @@
 
 int agr_port_getmedia(struct agr_port *, u_int *, u_int *);
 
+int agr_vlan_add(struct agr_port *, void *);
+int agr_vlan_del(struct agr_port *, void *);
+
 #endif /* !_NET_AGR_IF_AGRSUBR_H_ */



Home | Main Index | Thread Index | Old Index