Module Name: src
Committed By: ozaki-r
Date: Wed Dec 6 04:37:00 UTC 2017
Modified Files:
src/sys/net/agr: if_agr.c if_agrether.c if_agrsubr.c if_agrsubr.h
Log Message:
Simplify; share agr_vlan_add and agr_vlan_del (NFCI)
To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/net/agr/if_agr.c
cvs rdiff -u -r1.9 -r1.10 src/sys/net/agr/if_agrether.c
cvs rdiff -u -r1.10 -r1.11 src/sys/net/agr/if_agrsubr.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/agr/if_agrsubr.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/agr/if_agr.c
diff -u src/sys/net/agr/if_agr.c:1.41 src/sys/net/agr/if_agr.c:1.42
--- src/sys/net/agr/if_agr.c:1.41 Sat Jan 28 22:56:09 2017
+++ src/sys/net/agr/if_agr.c Wed Dec 6 04:37:00 2017
@@ -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 @@ agrport_ioctl(struct agr_port *port, u_l
/*
* 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_vlan_check(struct ifnet *ifp, struct
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;
}
}
Index: src/sys/net/agr/if_agrether.c
diff -u src/sys/net/agr/if_agrether.c:1.9 src/sys/net/agr/if_agrether.c:1.10
--- src/sys/net/agr/if_agrether.c:1.9 Wed Oct 19 01:49:50 2011
+++ src/sys/net/agr/if_agrether.c Wed Dec 6 04:37:00 2017
@@ -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 @@ agrether_portinit(struct agr_softc *sc,
}
/* 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 @@ agrether_portfini(struct agr_softc *sc,
}
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));
Index: src/sys/net/agr/if_agrsubr.c
diff -u src/sys/net/agr/if_agrsubr.c:1.10 src/sys/net/agr/if_agrsubr.c:1.11
--- src/sys/net/agr/if_agrsubr.c:1.10 Mon Aug 24 22:21:26 2015
+++ src/sys/net/agr/if_agrsubr.c Wed Dec 6 04:37:00 2017
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_agrsubr.c
#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 @@ agr_port_getmedia(struct agr_port *port,
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;
+}
Index: src/sys/net/agr/if_agrsubr.h
diff -u src/sys/net/agr/if_agrsubr.h:1.4 src/sys/net/agr/if_agrsubr.h:1.5
--- src/sys/net/agr/if_agrsubr.h:1.4 Wed Feb 21 23:00:07 2007
+++ src/sys/net/agr/if_agrsubr.h Wed Dec 6 04:37:00 2017
@@ -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_configmulti_ifreq(struct agr_sof
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_ */