Source-Changes-HG archive

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

[src/trunk]: src Rework the xxxVERBOSE option to share the common module-hook...



details:   https://anonhg.NetBSD.org/src/rev/6cd9a2b3e9a1
branches:  trunk
changeset: 379977:6cd9a2b3e9a1
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Jun 29 21:03:36 2021 +0000

description:
Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE.  This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
  of MII_STR_oui_model definitions and use of oui and model rather than
  vendor and product.  This also changes the compressed data in the
  xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
  digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
  very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
  DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
  xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
  (to deal with the vendor/product vs oui/model issue), we need to
  make sure it gets compiled with -Wno-error=format-nonliteral, even
  in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO).  This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.

diffstat:

 lib/libpci/Makefile                       |    4 +-
 sys/arch/arm/amlogic/gxlphy.c             |    9 +-
 sys/dev/dev_verbose.c                     |   17 +-
 sys/dev/dev_verbose.h                     |   41 +++---
 sys/dev/devlist2h.awk                     |   84 ++++++++++++--
 sys/dev/hdaudio/hdaudio.c                 |    5 +-
 sys/dev/mii/Makefile.miidevs              |   22 ++-
 sys/dev/mii/devlist2h.awk                 |  171 ------------------------------
 sys/dev/mii/gentbi.c                      |    9 +-
 sys/dev/mii/mii_physubr.c                 |   48 ++++---
 sys/dev/mii/mii_verbose.c                 |   42 +------
 sys/dev/mii/mii_verbose.h                 |   13 +-
 sys/dev/mii/miivar.h                      |    5 +-
 sys/dev/mii/ukphy.c                       |    8 +-
 sys/dev/pci/ixgbe/ixgbe.c                 |    9 +-
 sys/dev/pci/pci_subr.c                    |    6 +-
 sys/rump/librump/rumpdev/Makefile.rumpdev |    3 +-
 sys/sys/param.h                           |    4 +-
 18 files changed, 189 insertions(+), 311 deletions(-)

diffs (truncated from 981 to 300 lines):

diff -r 44bc095c2a42 -r 6cd9a2b3e9a1 lib/libpci/Makefile
--- a/lib/libpci/Makefile       Tue Jun 29 20:44:38 2021 +0000
+++ b/lib/libpci/Makefile       Tue Jun 29 21:03:36 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.5 2014/09/21 14:32:37 christos Exp $
+#      $NetBSD: Makefile,v 1.6 2021/06/29 21:03:36 pgoyette Exp $
 
 .include <bsd.own.mk>
 
@@ -10,6 +10,8 @@ SYSDIR= ${NETBSDSRCDIR}/sys/
 .PATH.c: ${SYSDIR}/dev/pci ${SYSDIR}/dev
 CPPFLAGS+= -I${SYSDIR}
 
+COPTS.dev_verbose.c+= -Wno-error=format-nonliteral
+
 MAN=   pci.3
 
 MLINKS=        pci.3 pcibus_conf_read.3 \
diff -r 44bc095c2a42 -r 6cd9a2b3e9a1 sys/arch/arm/amlogic/gxlphy.c
--- a/sys/arch/arm/amlogic/gxlphy.c     Tue Jun 29 20:44:38 2021 +0000
+++ b/sys/arch/arm/amlogic/gxlphy.c     Tue Jun 29 21:03:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gxlphy.c,v 1.4 2020/03/28 18:37:18 thorpej Exp $ */
+/* $NetBSD: gxlphy.c,v 1.5 2021/06/29 21:03:36 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2019 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gxlphy.c,v 1.4 2020/03/28 18:37:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gxlphy.c,v 1.5 2021/06/29 21:03:36 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -148,9 +148,10 @@ gxlphyattach(device_t parent, device_t s
        int oui = MII_OUI(ma->mii_id1, ma->mii_id2);
        int model = MII_MODEL(ma->mii_id2);
        int rev = MII_REV(ma->mii_id2);
-       const char *descr;
+       char descr[MII_MAX_DESCR_LEN];
 
-       if ((descr = mii_get_descr(oui, model)) != NULL)
+       mii_get_descr(descr, sizeof(descr), oui, model);
+       if (descr[0])
                aprint_normal(": %s (OUI 0x%06x, model 0x%04x), rev. %d\n",
                       descr, oui, model, rev);
        else
diff -r 44bc095c2a42 -r 6cd9a2b3e9a1 sys/dev/dev_verbose.c
--- a/sys/dev/dev_verbose.c     Tue Jun 29 20:44:38 2021 +0000
+++ b/sys/dev/dev_verbose.c     Tue Jun 29 21:03:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dev_verbose.c,v 1.3 2016/10/26 06:10:39 pgoyette Exp $ */
+/*     $NetBSD: dev_verbose.c,v 1.4 2021/06/29 21:03:36 pgoyette Exp $ */
 
 /*
  * Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dev_verbose.c,v 1.3 2016/10/26 06:10:39 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dev_verbose.c,v 1.4 2021/06/29 21:03:36 pgoyette Exp $");
 
 #include <sys/param.h>
 
@@ -37,7 +37,7 @@
 #include <dev/dev_verbose.h>
 
 static const char *
-dev_untokenstring(const char *words, const uint16_t *token, char *buf,
+dev_untokenstring(const char *words, const uint32_t *token, char *buf,
     size_t len)
 {
        char *cp = buf;
@@ -58,7 +58,8 @@ dev_untokenstring(const char *words, con
 
 const char *
 dev_findvendor(char *buf, size_t len, const char *words, size_t nwords,
-    const uint16_t *vendors, size_t nvendors, uint16_t vendor)
+    const uint32_t *vendors, size_t nvendors, uint32_t vendor,
+    const char *fmt)
 {
        size_t n;
 
@@ -72,14 +73,14 @@ dev_findvendor(char *buf, size_t len, co
                while (n < nvendors && vendors[n] != 0)
                        n++;
        }
-       snprintf(buf, len, "vendor %4.4x", vendor);
+       snprintf(buf, len, fmt, vendor);
        return NULL;
 }
 
 const char *
 dev_findproduct(char *buf, size_t len, const char *words, size_t nwords,
-    const uint16_t *products, size_t nproducts, uint16_t vendor,
-    uint16_t product)
+    const uint32_t *products, size_t nproducts, uint32_t vendor,
+    uint32_t product, const char *fmt)
 {
        size_t n;
 
@@ -93,6 +94,6 @@ dev_findproduct(char *buf, size_t len, c
                while (n < nproducts && products[n] != 0)
                        n++;
        }
-       snprintf(buf, len, "product %4.4x", product);
+       snprintf(buf, len, fmt, product);
        return NULL;
 }
diff -r 44bc095c2a42 -r 6cd9a2b3e9a1 sys/dev/dev_verbose.h
--- a/sys/dev/dev_verbose.h     Tue Jun 29 20:44:38 2021 +0000
+++ b/sys/dev/dev_verbose.h     Tue Jun 29 21:03:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dev_verbose.h,v 1.7 2021/06/15 23:24:57 riastradh Exp $ */
+/*     $NetBSD: dev_verbose.h,v 1.8 2021/06/29 21:03:36 pgoyette Exp $ */
 
 /*
  * Redistribution and use in source and binary forms, with or without
@@ -30,35 +30,36 @@
 #endif
 
 const char *dev_findvendor(char *, size_t, const char *, size_t, 
-       const uint16_t *, size_t, uint16_t);
+       const uint32_t *, size_t, uint32_t, const char *);
 const char *dev_findproduct(char *, size_t, const char *, size_t, 
-       const uint16_t *, size_t, uint16_t, uint16_t);
+       const uint32_t *, size_t, uint32_t, uint32_t, const char *);
 
 #define DEV_VERBOSE_COMMON_DEFINE(tag)                                 \
 static const char *                                                    \
-tag ## _findvendor_real(char *buf, size_t len, uint16_t vendor)                \
+tag ## _findvendor_real(char *buf, size_t len, uint32_t vendor)                \
 {                                                                      \
        return dev_findvendor(buf, len, tag ## _words,                  \
            __arraycount(tag ## _words), tag ## _vendors,               \
-           __arraycount(tag ## _vendors), vendor);                     \
+           __arraycount(tag ## _vendors), vendor, tag ## _id1_format); \
 }                                                                      \
                                                                        \
 static const char *                                                    \
-tag ## _findproduct_real(char *buf, size_t len, uint16_t vendor,       \
-    uint16_t product)                                                  \
+tag ## _findproduct_real(char *buf, size_t len, uint32_t vendor,       \
+    uint32_t product)                                                  \
 {                                                                      \
        return dev_findproduct(buf, len, tag ## _words,                 \
            __arraycount(tag ## _words), tag ## _products,              \
-           __arraycount(tag ## _products), vendor, product);           \
+           __arraycount(tag ## _products), vendor, product,            \
+           tag ## _id2_format);                                        \
 }                                                                      \
 
 #ifdef _KERNEL
 
 #define DEV_VERBOSE_KERNEL_DECLARE(tag)                                        \
 MODULE_HOOK(tag ## _findvendor_hook, const char *,                     \
-       (char *, size_t, uint16_t));                                    \
+       (char *, size_t, uint32_t));                                    \
 MODULE_HOOK(tag ## _findproduct_hook, const char *,                    \
-       (char *, size_t, uint16_t, uint16_t));                          \
+       (char *, size_t, uint32_t, uint32_t));                          \
 extern int tag ## verbose_loaded;
 
 #define DEV_VERBOSE_MODULE_DEFINE(tag, deps)                           \
@@ -91,8 +92,8 @@ MODULE(MODULE_CLASS_DRIVER, tag ## verbo
 #endif /* KERNEL */
 
 #define DEV_VERBOSE_DECLARE(tag)                                       \
-extern const char * tag ## _findvendor(char *, size_t, uint16_t);      \
-extern const char * tag ## _findproduct(char *, size_t, uint16_t, uint16_t)
+extern const char * tag ## _findvendor(char *, size_t, uint32_t);      \
+extern const char * tag ## _findproduct(char *, size_t, uint32_t, uint32_t)
 
 #if defined(_KERNEL)
 
@@ -111,27 +112,27 @@ tag ## _load_verbose(void)                                                \
 }                                                                      \
                                                                        \
 const char *                                                           \
-tag ## _findvendor(char *buf, size_t len, uint16_t vendor)             \
+tag ## _findvendor(char *buf, size_t len, uint32_t vendor)             \
 {                                                                      \
        const char *retval = NULL;                                      \
                                                                        \
        tag ## _load_verbose();                                         \
        MODULE_HOOK_CALL(tag ## _findvendor_hook, (buf, len, vendor),   \
-               (snprintf(buf, len, "vendor %4.4x", vendor), NULL),     \
+               (snprintf(buf, len, tag ## _id1_format, vendor), NULL), \
                retval);                                                \
        return retval;                                                  \
 }                                                                      \
                                                                        \
 const char *                                                           \
-tag ## _findproduct(char *buf, size_t len, uint16_t vendor,            \
-    uint16_t product)                                                  \
+tag ## _findproduct(char *buf, size_t len, uint32_t vendor,            \
+    uint32_t product)                                                  \
 {                                                                      \
        const char *retval = NULL;                                      \
                                                                        \
        tag ## _load_verbose();                                         \
        MODULE_HOOK_CALL(tag ## _findproduct_hook,                      \
                (buf, len, vendor, product),                            \
-               (snprintf(buf, len, "product %4.4x", product), NULL),   \
+               (snprintf(buf, len, tag ## _id2_format, product), NULL), \
                retval);                                                \
        return retval;                                                  \
 }                                                                      \
@@ -140,14 +141,14 @@ tag ## _findproduct(char *buf, size_t le
 
 #define DEV_VERBOSE_DEFINE(tag)                                                \
 DEV_VERBOSE_COMMON_DEFINE(tag)                                         \
-const char *tag ## _findvendor(char *buf, size_t len, uint16_t vendor) \
+const char *tag ## _findvendor(char *buf, size_t len, uint32_t vendor) \
 {                                                                      \
                                                                        \
        return tag ## _findvendor_real(buf, len, vendor);               \
 }                                                                      \
                                                                        \
-const char *tag ## _findproduct(char *buf, size_t len, uint16_t vendor,        \
-               uint16_t product)                                       \
+const char *tag ## _findproduct(char *buf, size_t len, uint32_t vendor,        \
+               uint32_t product)                                       \
 {                                                                      \
                                                                        \
        return tag ## _findproduct_real(buf, len, vendor, product);     \
diff -r 44bc095c2a42 -r 6cd9a2b3e9a1 sys/dev/devlist2h.awk
--- a/sys/dev/devlist2h.awk     Tue Jun 29 20:44:38 2021 +0000
+++ b/sys/dev/devlist2h.awk     Tue Jun 29 21:03:36 2021 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/awk -f
-#      $NetBSD: devlist2h.awk,v 1.3 2017/06/27 08:09:14 wiz Exp $
+#      $NetBSD: devlist2h.awk,v 1.4 2021/06/29 21:03:36 pgoyette Exp $
 #
 # Copyright (c) 1995, 1996 Christopher G. Demetriou
 # All rights reserved.
@@ -29,6 +29,34 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
+
+function collectline(f) {
+       oparen = 0 
+       line = ""
+       while (f <= NF) {
+               if ($f == "#") {
+                       line = line "("
+                       oparen = 1
+                       f++
+                       continue
+               }
+               if (oparen) {  
+                       line = line $f
+                       if (f < NF)
+                       line = line " "
+                       f++
+                       continue
+               }
+               line = line $f
+               if (f < NF)
+                       line = line " "
+               f++
+       }
+       if (oparen)
+               line = line ")"
+       return line
+}
+
 NR == 1 {
        nproducts = nvendors = blanklines = 0
        vendormaxlen = productmaxlen = 0
@@ -42,6 +70,22 @@ NR == 1 {
        gsub("\\$", "", VERSION)
        gsub(/ $/, "", VERSION)
 
+       if ( PREFIX == "MII" ) {
+               VENDOR="OUI"
+               PRODUCT="MODEL"
+               vendor="oui"
+               product="model"
+               fmt_vendor="oui %6.6x"
+               fmt_product="model %4.4x"
+       } else {
+               VENDOR="VENDOR"
+               PRODUCT="PRODUCT"
+               vendor="vendor"
+               product="product"
+               fmt_vendor="vendor %4.4x"
+               fmt_product="product %4.4x"
+       }
+
        printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
        printf("/*\n") > dfile
        printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
@@ -62,13 +106,13 @@ NR == 1 {
 
        next



Home | Main Index | Thread Index | Old Index