Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/mii Update miiverbose module to use module_autoload(...
details: https://anonhg.NetBSD.org/src/rev/dbca3edccf54
branches: trunk
changeset: 755458:dbca3edccf54
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sun Jun 06 18:58:22 2010 +0000
description:
Update miiverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.
diffstat:
sys/dev/mii/mii_physubr.c | 36 ++++++++++++++++++------------------
sys/dev/mii/mii_verbose.c | 10 +++++++---
sys/dev/mii/mii_verbose.h | 6 ++++--
sys/dev/mii/ukphy.c | 5 ++---
4 files changed, 31 insertions(+), 26 deletions(-)
diffs (146 lines):
diff -r 6eeb36968268 -r dbca3edccf54 sys/dev/mii/mii_physubr.c
--- a/sys/dev/mii/mii_physubr.c Sun Jun 06 18:56:10 2010 +0000
+++ b/sys/dev/mii/mii_physubr.c Sun Jun 06 18:58:22 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mii_physubr.c,v 1.69 2010/06/02 19:47:34 martin Exp $ */
+/* $NetBSD: mii_physubr.c,v 1.70 2010/06/06 18:58:22 pgoyette Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.69 2010/06/02 19:47:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.70 2010/06/06 18:58:22 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -55,29 +55,29 @@
const char *(*mii_get_descr)(int, int) = mii_get_descr_stub;
+int mii_verbose_loaded = 0;
+
const char *mii_get_descr_stub(int oui, int model)
{
- return NULL;
+ mii_load_verbose();
+ if (mii_verbose_loaded)
+ return mii_get_descr(oui, model);
+ else
+ return NULL;
}
/*
- * Routine to load/unload the miiverbose kernel module as needed
+ * Routine to load the miiverbose kernel module as needed
*/
-void mii_verbose_ctl(bool load)
+void mii_load_verbose(void)
{
- static int loaded = 0;
-
- if (load) {
- if (loaded++ == 0)
- if (module_load("miiverbose", MODCTL_LOAD_FORCE,
- NULL, MODULE_CLASS_MISC) !=0 )
- loaded = 0;
- return;
- }
- if (loaded == 0)
- return;
- if (--loaded == 0)
- module_unload("miiverbose");
+ if (mii_verbose_loaded)
+ return;
+
+ mutex_enter(&module_lock);
+ if (module_autoload("miiverbose", MODULE_CLASS_MISC) ==0)
+ mii_verbose_loaded++;
+ mutex_exit(&module_lock);
}
static void mii_phy_statusmsg(struct mii_softc *);
diff -r 6eeb36968268 -r dbca3edccf54 sys/dev/mii/mii_verbose.c
--- a/sys/dev/mii/mii_verbose.c Sun Jun 06 18:56:10 2010 +0000
+++ b/sys/dev/mii/mii_verbose.c Sun Jun 06 18:58:22 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mii_verbose.c,v 1.1 2010/05/30 17:44:07 pgoyette Exp $ */
+/* $NetBSD: mii_verbose.c,v 1.2 2010/06/06 18:58:22 pgoyette Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mii_verbose.c,v 1.1 2010/05/30 17:44:07 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mii_verbose.c,v 1.2 2010/06/06 18:58:22 pgoyette Exp $");
#include <sys/module.h>
#include <dev/mii/mii_verbose.h>
@@ -75,12 +75,16 @@
static int
miiverbose_modcmd(modcmd_t cmd, void *arg)
{
+ static const char *(*saved_mii_get_descr)(int, int);
+
switch (cmd) {
case MODULE_CMD_INIT:
+ saved_mii_get_descr = mii_get_descr;
mii_get_descr = mii_get_descr_real;
return 0;
case MODULE_CMD_FINI:
- mii_get_descr = mii_get_descr_stub;
+ mii_get_descr = saved_mii_get_descr;
+ mii_verbose_loaded = 0;
return 0;
default:
return ENOTTY;
diff -r 6eeb36968268 -r dbca3edccf54 sys/dev/mii/mii_verbose.h
--- a/sys/dev/mii/mii_verbose.h Sun Jun 06 18:56:10 2010 +0000
+++ b/sys/dev/mii/mii_verbose.h Sun Jun 06 18:58:22 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mii_verbose.h,v 1.1 2010/05/30 17:44:08 pgoyette Exp $ */
+/* $NetBSD: mii_verbose.h,v 1.2 2010/06/06 18:58:22 pgoyette Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -40,7 +40,9 @@
extern const char * (*mii_get_descr)(int, int);
const char * mii_get_descr_stub(int, int);
-void mii_verbose_ctl(bool);
+void mii_load_verbose(void);
+
+extern int mii_verbose_loaded;
#endif /* _KERNEL */
diff -r 6eeb36968268 -r dbca3edccf54 sys/dev/mii/ukphy.c
--- a/sys/dev/mii/ukphy.c Sun Jun 06 18:56:10 2010 +0000
+++ b/sys/dev/mii/ukphy.c Sun Jun 06 18:58:22 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ukphy.c,v 1.42 2010/06/02 19:47:34 martin Exp $ */
+/* $NetBSD: ukphy.c,v 1.43 2010/06/06 18:58:22 pgoyette Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ukphy.c,v 1.42 2010/06/02 19:47:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukphy.c,v 1.43 2010/06/06 18:58:22 pgoyette Exp $");
#include "opt_mii.h"
@@ -110,7 +110,6 @@
int rev = MII_REV(ma->mii_id2);
const char *descr;
- mii_verbose_ctl(true);
if ((descr = mii_get_descr(oui, model)) != NULL)
aprint_normal(": %s (OUI 0x%06x, model 0x%04x), rev. %d\n",
descr, oui, model, rev);
Home |
Main Index |
Thread Index |
Old Index