Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Modularize the ld driver and all of its attachments....



details:   https://anonhg.NetBSD.org/src/rev/d8446624f852
branches:  trunk
changeset: 347966:d8446624f852
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Sep 27 03:33:32 2016 +0000

description:
Modularize the ld driver and all of its attachments.  Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).

diffstat:

 sys/dev/ata/ata_raid.c   |  105 ++++++++++++++++++++++++++++++++++++++--------
 sys/dev/ata/ld_ataraid.c |   54 ++++++++++++++++++++++-
 sys/dev/eisa/cac_eisa.c  |   53 +++++++++++++++++++++--
 sys/dev/eisa/mlx_eisa.c  |   61 +++++++++++++++++++++++++--
 sys/dev/ic/aac.c         |   72 +++++++++++++++++++++++++------
 sys/dev/ic/aacvar.h      |    3 +-
 sys/dev/ic/cac.c         |   73 +++++++++++++++++++++++++++-----
 sys/dev/ic/cacvar.h      |    4 +-
 sys/dev/ic/ld_aac.c      |   51 +++++++++++++++++++++-
 sys/dev/ic/ld_cac.c      |   51 +++++++++++++++++++++-
 sys/dev/ic/ld_icp.c      |   51 +++++++++++++++++++++-
 sys/dev/ic/ld_mlx.c      |   51 +++++++++++++++++++++-
 sys/dev/ic/ld_nvme.c     |   50 +++++++++++++++++++++-
 sys/dev/ic/mlx.c         |   50 +++++++++++++++++----
 sys/dev/ic/mlxvar.h      |    3 +-
 sys/dev/ic/nvme.c        |   32 +++++++++----
 sys/dev/ic/nvmevar.h     |    3 +-
 sys/dev/ld.c             |   46 ++++++++++++++++++-
 sys/dev/pci/aac_pci.c    |   16 +++++-
 sys/dev/pci/amr.c        |   82 +++++++++++++++++++++++++++++-------
 sys/dev/pci/cac_pci.c    |   52 +++++++++++++++++++++-
 sys/dev/pci/icp_pci.c    |   17 +++++-
 sys/dev/pci/if_vioif.c   |   36 +++++++++++++++-
 sys/dev/pci/ld_amr.c     |   50 +++++++++++++++++++++-
 sys/dev/pci/ld_twa.c     |   51 +++++++++++++++++++++-
 sys/dev/pci/ld_twe.c     |   51 +++++++++++++++++++++-
 sys/dev/pci/ld_virtio.c  |   50 +++++++++++++++++++++-
 sys/dev/pci/mlx_pci.c    |   59 ++++++++++++++++++++++++-
 sys/dev/pci/nvme_pci.c   |   49 ++++++++-------------
 sys/dev/pci/twa.c        |   63 ++++++++++++++++++++++-----
 sys/dev/pci/twe.c        |   60 +++++++++++++++++++++++---
 sys/dev/pci/viomb.c      |   37 +++++++++++++++-
 sys/dev/pci/virtio.c     |   81 ++++++++++++++++++++++++++++--------
 sys/dev/pci/virtiovar.h  |    3 +-
 sys/dev/sdmmc/ld_sdmmc.c |   50 +++++++++++++++++++++-
 35 files changed, 1400 insertions(+), 220 deletions(-)

diffs (truncated from 3043 to 300 lines):

diff -r 84deb4e348b1 -r d8446624f852 sys/dev/ata/ata_raid.c
--- a/sys/dev/ata/ata_raid.c    Tue Sep 27 02:33:16 2016 +0000
+++ b/sys/dev/ata/ata_raid.c    Tue Sep 27 03:33:32 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata_raid.c,v 1.37 2016/07/14 10:19:05 msaitoh Exp $    */
+/*     $NetBSD: ata_raid.c,v 1.38 2016/09/27 03:33:32 pgoyette Exp $   */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata_raid.c,v 1.37 2016/07/14 10:19:05 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_raid.c,v 1.38 2016/09/27 03:33:32 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -53,6 +53,7 @@
 #include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/proc.h>
+#include <sys/module.h>
 
 #include <miscfs/specfs/specdev.h>
 
@@ -74,16 +75,19 @@
 
 static int     ataraid_match(device_t, cfdata_t, void *);
 static void    ataraid_attach(device_t, device_t, void *);
+static int     ataraid_rescan(device_t, const char *, const int *);
 static int     ataraid_print(void *, const char *);
 
 static int     ata_raid_finalize(device_t);
 
+static int     finalize_done;
+
 ataraid_array_info_list_t ataraid_array_info_list =
     TAILQ_HEAD_INITIALIZER(ataraid_array_info_list);
 u_int ataraid_array_info_count;
 
-CFATTACH_DECL_NEW(ataraid, 0,
-    ataraid_match, ataraid_attach, NULL, NULL);
+CFATTACH_DECL3_NEW(ataraid, 0,
+    ataraid_match, ataraid_attach, NULL, NULL, ataraid_rescan, NULL, 0);
 
 /*
  * ataraidattach:
@@ -98,12 +102,29 @@
         * Register a finalizer which will be used to actually configure
         * the logical disks configured by ataraid.
         */
+       finalize_done = 0;
        if (config_finalize_register(NULL, ata_raid_finalize) != 0)
                aprint_normal("WARNING: "
                    "unable to register ATA RAID finalizer\n");
 }
 
 /*
+ * Use the config_finalizer to rescan for new devices, since the
+ * ld_ataraid driver might not be immediately available.
+ */
+
+/* ARGSUSED */
+static int
+ataraid_rescan(device_t self, const char *attr, const int *flags)
+{
+
+       finalize_done = 0;
+       (void)ata_raid_finalize(self);
+
+       return 0;
+}
+
+/*
  * ata_raid_type_name:
  *
  *     Return the type of ATA RAID.
@@ -140,34 +161,23 @@
                .cf_unit = 0,
                .cf_fstate = FSTATE_STAR,
        };
-       extern struct cfdriver ataraid_cd;
-       static int done_once;
-       int error;
 
        /*
-        * Since we only handle real hardware, we only need to be
-        * called once.
+        * Only run once for each instantiation
         */
-       if (done_once)
-               return (0);
-       done_once = 1;
+       if (finalize_done)
+               return 0;
+       finalize_done = 1;
 
        if (TAILQ_EMPTY(&ataraid_array_info_list))
                goto out;
 
-       error = config_cfattach_attach(ataraid_cd.cd_name, &ataraid_ca);
-       if (error) {
-               printf("%s: unable to register cfattach, error = %d\n",
-                   ataraid_cd.cd_name, error);
-               (void) config_cfdriver_detach(&ataraid_cd);
-               goto out;
-       }
-
        if (config_attach_pseudo(&ataraid_cfdata) == NULL)
                printf("%s: unable to attach an instance\n",
                    ataraid_cd.cd_name);
 
  out:
+printf("%s: exit\n", __func__);
        return (1);
 }
 
@@ -311,3 +321,58 @@
        putiobuf(bp);
        return (error);
 }
+
+MODULE(MODULE_CLASS_DRIVER, ataraid, "");
+ 
+#ifdef _MODULE
+CFDRIVER_DECL(ataraid, DV_DISK, NULL);
+#endif
+ 
+static int
+ataraid_modcmd(modcmd_t cmd, void *arg)
+{
+        int error = 0; 
+   
+        switch (cmd) {
+        case MODULE_CMD_INIT:
+#ifdef _MODULE
+               error = config_cfdriver_attach(&ataraid_cd);
+               if (error) 
+                       break;
+
+               error = config_cfattach_attach(ataraid_cd.cd_name, &ataraid_ca);
+               if (error) {
+                       config_cfdriver_detach(&ataraid_cd);
+                       aprint_error("%s: unable to register cfattach for \n"
+                           "%s, error %d", __func__, ataraid_cd.cd_name,
+                           error);
+                       break;
+               }
+#endif
+               break;
+       case MODULE_CMD_FINI:
+#ifdef _MODULE
+
+               error = config_cfattach_detach(ataraid_cd.cd_name, &ataraid_ca);
+               if (error) {
+                       aprint_error("%s: failed to detach %s cfattach, "
+                           "error %d\n", __func__, ataraid_cd.cd_name, error);
+                       break;
+               }
+               error = config_cfdriver_detach(&ataraid_cd);
+               if (error) {
+                       (void)config_cfattach_attach(ataraid_cd.cd_name,
+                           &ataraid_ca);
+                       aprint_error("%s: failed to detach %s cfdriver, "
+                           "error %d\n", __func__, ataraid_cd.cd_name, error);
+                       break;
+               }
+#endif
+               break;
+       case MODULE_CMD_STAT:
+       default:
+               error = ENOTTY;
+       }
+
+       return error;
+}
diff -r 84deb4e348b1 -r d8446624f852 sys/dev/ata/ld_ataraid.c
--- a/sys/dev/ata/ld_ataraid.c  Tue Sep 27 02:33:16 2016 +0000
+++ b/sys/dev/ata/ld_ataraid.c  Tue Sep 27 03:33:32 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_ataraid.c,v 1.42 2016/09/16 15:20:50 jdolecek Exp $ */
+/*     $NetBSD: ld_ataraid.c,v 1.43 2016/09/27 03:33:32 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -47,10 +47,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.42 2016/09/16 15:20:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.43 2016/09/27 03:33:32 pgoyette Exp $");
 
+#if defined(_KERNEL_OPT)
 #include "bio.h"
-
+#endif
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -66,6 +67,7 @@
 #include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/kauth.h>
+#include <sys/module.h>
 #if NBIO > 0
 #include <dev/ata/atavar.h>
 #include <dev/ata/atareg.h>
@@ -80,6 +82,8 @@
 
 #include <dev/ata/ata_raidvar.h>
 
+#include "ioconf.h"
+
 struct ld_ataraid_softc {
        struct ld_softc sc_ld;
 
@@ -711,3 +715,47 @@
        return 0;
 }
 #endif /* NBIO > 0 */
+
+MODULE(MODULE_CLASS_DRIVER, ld_ataraid, "ld,ataraid");
+
+#ifdef _MODULE
+/*
+ * XXX Don't allow ioconf.c to redefine the "struct cfdriver ld_ataraid"
+ * XXX it will be defined in the common-code module
+ */     
+#undef  CFDRIVER_DECL
+#define CFDRIVER_DECL(name, class, attr)
+#include "ioconf.c"
+#endif 
+  
+static int
+ld_ataraid_modcmd(modcmd_t cmd, void *opaque)
+{ 
+#ifdef _MODULE
+       /*
+        * We ignore the cfdriver_vec[] that ioconf provides, since
+        * the cfdrivers are attached already.
+        */
+       static struct cfdriver * const no_cfdriver_vec[] = { NULL };
+#endif
+       int error = 0;
+ 
+#ifdef _MODULE
+       switch (cmd) {
+       case MODULE_CMD_INIT:
+               error = config_init_component(no_cfdriver_vec,
+                   cfattach_ioconf_ld_ataraid, cfdata_ioconf_ld_ataraid);
+               break;
+       case MODULE_CMD_FINI:
+               error = config_fini_component(no_cfdriver_vec,
+                   cfattach_ioconf_ld_ataraid, cfdata_ioconf_ld_ataraid);
+               break;
+       default:
+               error = ENOTTY;
+       break;
+       }
+printf("%s: return %d\n", __func__, error);
+#endif
+
+       return error;
+}
diff -r 84deb4e348b1 -r d8446624f852 sys/dev/eisa/cac_eisa.c
--- a/sys/dev/eisa/cac_eisa.c   Tue Sep 27 02:33:16 2016 +0000
+++ b/sys/dev/eisa/cac_eisa.c   Tue Sep 27 03:33:32 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cac_eisa.c,v 1.24 2016/07/14 10:19:06 msaitoh Exp $    */
+/*     $NetBSD: cac_eisa.c,v 1.25 2016/09/27 03:33:32 pgoyette Exp $   */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -61,12 +61,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cac_eisa.c,v 1.24 2016/07/14 10:19:06 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cac_eisa.c,v 1.25 2016/09/27 03:33:32 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/device.h>
-
+#include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/intr.h>
 
@@ -76,6 +76,8 @@
 #include <dev/ic/cacreg.h>
 #include <dev/ic/cacvar.h>
 
+#include "ioconf.h"
+
 #define CAC_EISA_SLOT_OFFSET           0x0c88
 #define CAC_EISA_IOSIZE                        0x0017
 #define CAC_EISA_IOCONF                        0x38
@@ -89,8 +91,8 @@
 static int     cac_eisa_l0_intr_pending(struct cac_softc *);



Home | Main Index | Thread Index | Old Index