Source-Changes-HG archive

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

[src/trunk]: src Extract SCSIVERBOSE into a kernel module. The module can be...



details:   https://anonhg.NetBSD.org/src/rev/02ee977d8ad4
branches:  trunk
changeset: 755267:02ee977d8ad4
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun May 30 04:38:03 2010 +0000

description:
Extract SCSIVERBOSE into a kernel module.  The module can be builtin
by defining 'options SCSIVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.

The module is built for all architectures, whether or not SCSI or
atapi support exists.

diffstat:

 distrib/sets/lists/modules/mi    |    4 +-
 sys/dev/scsipi/atapiconf.c       |    6 +-
 sys/dev/scsipi/scsiconf.c        |    6 +-
 sys/dev/scsipi/scsipi_base.c     |  106 ++++++++++++++++++++++----------------
 sys/dev/scsipi/scsipi_verbose.c  |   49 +++++++++++++++--
 sys/dev/scsipi/scsipiconf.c      |   27 +++++++++-
 sys/dev/scsipi/scsipiconf.h      |   18 ++++--
 sys/dev/scsipi/st.c              |   14 ++--
 sys/modules/Makefile             |    3 +-
 sys/modules/scsiverbose/Makefile |   10 +++
 10 files changed, 170 insertions(+), 73 deletions(-)

diffs (truncated from 538 to 300 lines):

diff -r 2deef12934c5 -r 02ee977d8ad4 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Sun May 30 04:32:09 2010 +0000
+++ b/distrib/sets/lists/modules/mi     Sun May 30 04:38:03 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.15 2010/05/29 01:14:30 pgoyette Exp $
+# $NetBSD: mi,v 1.16 2010/05/30 04:38:04 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -98,6 +98,8 @@
 ./@MODULEDIR@/puffs/puffs.kmod                 base-kernel-modules     kmod
 ./@MODULEDIR@/putter                           base-kernel-modules     kmod
 ./@MODULEDIR@/putter/putter.kmod               base-kernel-modules     kmod
+./@MODULEDIR@/scsiverbose                      base-kernel-modules     kmod
+./@MODULEDIR@/scsiverbose/scsiverbose.kmod     base-kernel-modules     kmod
 ./@MODULEDIR@/sdt                              base-kernel-modules     kmod,dtrace
 ./@MODULEDIR@/sdt/sdt.kmod                     base-kernel-modules     kmod,dtrace
 ./@MODULEDIR@/secmodel_bsd44                   base-kernel-modules     kmod
diff -r 2deef12934c5 -r 02ee977d8ad4 sys/dev/scsipi/atapiconf.c
--- a/sys/dev/scsipi/atapiconf.c        Sun May 30 04:32:09 2010 +0000
+++ b/sys/dev/scsipi/atapiconf.c        Sun May 30 04:38:03 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atapiconf.c,v 1.81 2009/11/12 19:44:17 dyoung Exp $    */
+/*     $NetBSD: atapiconf.c,v 1.82 2010/05/30 04:38:04 pgoyette Exp $  */
 
 /*
  * Copyright (c) 1996, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.81 2009/11/12 19:44:17 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.82 2010/05/30 04:38:04 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -160,6 +160,7 @@
                aprint_error_dev(self, "couldn't establish power handler\n");
 
        /* Probe the bus for devices. */
+       scsipi_verbose_ctl(true);
        atapi_probe_bus(sc, -1);
 }
 
@@ -206,6 +207,7 @@
                        return (error);
                KASSERT(scsipi_lookup_periph(chan, target, 0) == NULL);
        }
+       scsipi_verbose_ctl(false);
        return (0);
 }
 
diff -r 2deef12934c5 -r 02ee977d8ad4 sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Sun May 30 04:32:09 2010 +0000
+++ b/sys/dev/scsipi/scsiconf.c Sun May 30 04:38:03 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsiconf.c,v 1.256 2010/04/27 18:55:12 dyoung Exp $    */
+/*     $NetBSD: scsiconf.c,v 1.257 2010/05/30 04:38:04 pgoyette Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.256 2010/04/27 18:55:12 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.257 2010/05/30 04:38:04 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -182,6 +182,7 @@
        scsi_initq = malloc(sizeof(struct scsi_initq), M_DEVBUF, M_WAITOK);
        scsi_initq->sc_channel = chan;
        TAILQ_INSERT_TAIL(&scsi_initq_head, scsi_initq, scsi_initq);
+       scsipi_verbose_ctl(true);
         config_pending_incr();
        if (scsipi_channel_init(chan)) {
                aprint_error_dev(sc->sc_dev, "failed to init channel\n");
@@ -225,6 +226,7 @@
        simple_lock(&scsibus_interlock);
        TAILQ_REMOVE(&scsi_initq_head, scsi_initq, scsi_initq);
        simple_unlock(&scsibus_interlock);
+       scsipi_verbose_ctl(false);
 
        free(scsi_initq, M_DEVBUF);
        wakeup(&scsi_initq_head);
diff -r 2deef12934c5 -r 02ee977d8ad4 sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c      Sun May 30 04:32:09 2010 +0000
+++ b/sys/dev/scsipi/scsipi_base.c      Sun May 30 04:38:03 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipi_base.c,v 1.151 2010/02/12 11:39:33 pooka Exp $  */
+/*     $NetBSD: scsipi_base.c,v 1.152 2010/05/30 04:38:04 pgoyette Exp $       */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.151 2010/02/12 11:39:33 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.152 2010/05/30 04:38:04 pgoyette Exp $");
 
 #include "opt_scsi.h"
 
@@ -47,6 +47,7 @@
 #include <sys/proc.h>
 #include <sys/kthread.h>
 #include <sys/hash.h>
+#include <sys/module.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -82,6 +83,27 @@
 
 static struct pool scsipi_xfer_pool;
 
+/*              
+ * Load/unload the scsiverbose module
+ */
+void
+scsipi_verbose_ctl(bool load)
+{
+       static int loaded = 0;
+ 
+       if (load) {
+               if (loaded++ == 0)
+                       if (module_load("scsiverbose", MODCTL_LOAD_FORCE,
+                                       NULL, MODULE_CLASS_MISC) != 0)
+               loaded = 0;
+               return;
+       }
+       if (loaded == 0)
+               return;
+       if (--loaded == 0)
+               module_unload("scsiverbose");
+} 
+
 /*
  * scsipi_init:
  *
@@ -707,7 +729,7 @@
 /*
  * scsipi_print_cdb:
  * prints a command descriptor block (for debug purpose, error messages,
- * SCSIPI_VERBOSE, ...)
+ * SCSIVERBOSE, ...)
  */
 void
 scsipi_print_cdb(struct scsipi_generic *cmd)
@@ -768,7 +790,6 @@
        struct scsipi_periph *periph = xs->xs_periph;
        u_int8_t key;
        int error;
-#ifndef        SCSIVERBOSE
        u_int32_t info;
        static const char *error_mes[] = {
                "soft error (corrected)",
@@ -780,7 +801,6 @@
                "search returned equal", "volume overflow",
                "verify miscompare", "unknown error key"
        };
-#endif
 
        sense = &xs->sense.scsi_sense;
 #ifdef SCSIPI_DEBUG
@@ -857,12 +877,10 @@
                printf(" DEFERRED ERROR, key = 0x%x\n", key);
                /* FALLTHROUGH */
        case 0x70:
-#ifndef        SCSIVERBOSE
                if ((sense->response_code & SSD_RCODE_VALID) != 0)
                        info = _4btol(sense->info);
                else
                        info = 0;
-#endif
                key = SSD_SENSE_KEY(sense->flags);
 
                switch (key) {
@@ -947,44 +965,44 @@
                        break;
                }
 
-#ifdef SCSIVERBOSE
-               if (key && (xs->xs_control & XS_CTL_SILENT) == 0)
-                       scsipi_print_sense(xs, 0);
-#else
-               if (key) {
-                       scsipi_printaddr(periph);
-                       printf("%s", error_mes[key - 1]);
-                       if ((sense->response_code & SSD_RCODE_VALID) != 0) {
-                               switch (key) {
-                               case SKEY_NOT_READY:
-                               case SKEY_ILLEGAL_REQUEST:
-                               case SKEY_UNIT_ATTENTION:
-                               case SKEY_DATA_PROTECT:
-                                       break;
-                               case SKEY_BLANK_CHECK:
-                                       printf(", requested size: %d (decimal)",
-                                           info);
-                                       break;
-                               case SKEY_ABORTED_COMMAND:
-                                       if (xs->xs_retries)
-                                               printf(", retrying");
-                                       printf(", cmd 0x%x, info 0x%x",
-                                           xs->cmd->opcode, info);
-                                       break;
-                               default:
-                                       printf(", info = %d (decimal)", info);
-                               }
+               /* Print verbose decode if appropriate and possible */
+               if ((key == 0) ||
+                   ((xs->xs_control & XS_CTL_SILENT) != 0) ||
+                   (scsipi_print_sense(xs, 0) != 0))
+                       return (error);
+
+               /* Print brief(er) sense information */
+               scsipi_printaddr(periph);
+               printf("%s", error_mes[key - 1]);
+               if ((sense->response_code & SSD_RCODE_VALID) != 0) {
+                       switch (key) {
+                       case SKEY_NOT_READY:
+                       case SKEY_ILLEGAL_REQUEST:
+                       case SKEY_UNIT_ATTENTION:
+                       case SKEY_DATA_PROTECT:
+                               break;
+                       case SKEY_BLANK_CHECK:
+                               printf(", requested size: %d (decimal)",
+                                   info);
+                               break;
+                       case SKEY_ABORTED_COMMAND:
+                               if (xs->xs_retries)
+                                       printf(", retrying");
+                               printf(", cmd 0x%x, info 0x%x",
+                                   xs->cmd->opcode, info);
+                               break;
+                       default:
+                               printf(", info = %d (decimal)", info);
                        }
-                       if (sense->extra_len != 0) {
-                               int n;
-                               printf(", data =");
-                               for (n = 0; n < sense->extra_len; n++)
-                                       printf(" %02x",
-                                           sense->csi[n]);
-                       }
-                       printf("\n");
                }
-#endif
+               if (sense->extra_len != 0) {
+                       int n;
+                       printf(", data =");
+                       for (n = 0; n < sense->extra_len; n++)
+                               printf(" %02x",
+                                   sense->csi[n]);
+               }
+               printf("\n");
                return (error);
 
        /*
@@ -1441,9 +1459,7 @@
                        if (xs->resid < xs->datalen) {
                                printf("we read %d bytes of sense anyway:\n",
                                    xs->datalen - xs->resid);
-#ifdef SCSIVERBOSE
                                scsipi_print_sense_data((void *)xs->data, 0);
-#endif
                        }
                        return EINVAL;
                }
diff -r 2deef12934c5 -r 02ee977d8ad4 sys/dev/scsipi/scsipi_verbose.c
--- a/sys/dev/scsipi/scsipi_verbose.c   Sun May 30 04:32:09 2010 +0000
+++ b/sys/dev/scsipi/scsipi_verbose.c   Sun May 30 04:38:03 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipi_verbose.c,v 1.29 2008/04/28 20:23:58 martin Exp $       */
+/*     $NetBSD: scsipi_verbose.c,v 1.30 2010/05/30 04:38:04 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_verbose.c,v 1.29 2008/04/28 20:23:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_verbose.c,v 1.30 2010/05/30 04:38:04 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -39,8 +39,7 @@
 
 #ifdef _KERNEL
 #include <sys/systm.h>
-
-#include "opt_scsi.h"
+#include <sys/module.h>
 #else
 #include <stdio.h>
 #endif
@@ -48,6 +47,10 @@
 #include <dev/scsipi/scsipiconf.h>
 #include <dev/scsipi/scsiconf.h>



Home | Main Index | Thread Index | Old Index