Module Name: src Committed By: pgoyette Date: Sun May 30 04:38:04 UTC 2010
Modified Files: src/distrib/sets/lists/modules: mi src/sys/dev/scsipi: atapiconf.c scsiconf.c scsipi_base.c scsipi_verbose.c scsipiconf.c scsipiconf.h st.c src/sys/modules: Makefile Added Files: src/sys/modules/scsiverbose: Makefile Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/distrib/sets/lists/modules/mi cvs rdiff -u -r1.81 -r1.82 src/sys/dev/scsipi/atapiconf.c cvs rdiff -u -r1.256 -r1.257 src/sys/dev/scsipi/scsiconf.c cvs rdiff -u -r1.151 -r1.152 src/sys/dev/scsipi/scsipi_base.c cvs rdiff -u -r1.29 -r1.30 src/sys/dev/scsipi/scsipi_verbose.c cvs rdiff -u -r1.36 -r1.37 src/sys/dev/scsipi/scsipiconf.c cvs rdiff -u -r1.116 -r1.117 src/sys/dev/scsipi/scsipiconf.h cvs rdiff -u -r1.216 -r1.217 src/sys/dev/scsipi/st.c cvs rdiff -u -r1.43 -r1.44 src/sys/modules/Makefile cvs rdiff -u -r0 -r1.1 src/sys/modules/scsiverbose/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/modules/mi diff -u src/distrib/sets/lists/modules/mi:1.15 src/distrib/sets/lists/modules/mi:1.16 --- src/distrib/sets/lists/modules/mi:1.15 Sat May 29 01:14:30 2010 +++ src/distrib/sets/lists/modules/mi Sun May 30 04:38:04 2010 @@ -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 Index: src/sys/dev/scsipi/atapiconf.c diff -u src/sys/dev/scsipi/atapiconf.c:1.81 src/sys/dev/scsipi/atapiconf.c:1.82 --- src/sys/dev/scsipi/atapiconf.c:1.81 Thu Nov 12 19:44:17 2009 +++ src/sys/dev/scsipi/atapiconf.c Sun May 30 04:38:04 2010 @@ -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); } Index: src/sys/dev/scsipi/scsiconf.c diff -u src/sys/dev/scsipi/scsiconf.c:1.256 src/sys/dev/scsipi/scsiconf.c:1.257 --- src/sys/dev/scsipi/scsiconf.c:1.256 Tue Apr 27 18:55:12 2010 +++ src/sys/dev/scsipi/scsiconf.c Sun May 30 04:38:04 2010 @@ -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); Index: src/sys/dev/scsipi/scsipi_base.c diff -u src/sys/dev/scsipi/scsipi_base.c:1.151 src/sys/dev/scsipi/scsipi_base.c:1.152 --- src/sys/dev/scsipi/scsipi_base.c:1.151 Fri Feb 12 11:39:33 2010 +++ src/sys/dev/scsipi/scsipi_base.c Sun May 30 04:38:04 2010 @@ -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); - } - } - if (sense->extra_len != 0) { - int n; - printf(", data ="); - for (n = 0; n < sense->extra_len; n++) - printf(" %02x", - sense->csi[n]); + /* 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); } - 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; } Index: src/sys/dev/scsipi/scsipi_verbose.c diff -u src/sys/dev/scsipi/scsipi_verbose.c:1.29 src/sys/dev/scsipi/scsipi_verbose.c:1.30 --- src/sys/dev/scsipi/scsipi_verbose.c:1.29 Mon Apr 28 20:23:58 2008 +++ src/sys/dev/scsipi/scsipi_verbose.c Sun May 30 04:38:04 2010 @@ -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> +int scsipi_print_sense_real(struct scsipi_xfer *, int); +void scsipi_print_sense_data_real(struct scsi_sense_data *, int); +char *scsipi_decode_sense_real(void *, int); + static const char *sense_keys[16] = { "No Additional Sense", "Recovered Error", @@ -597,6 +600,35 @@ { 0x00, 0x00, NULL } }; +#ifdef _KERNEL +MODULE(MODULE_CLASS_MISC, scsiverbose, NULL); + +static int +scsiverbose_modcmd(modcmd_t cmd, void *arg) +{ + switch (cmd) { + case MODULE_CMD_INIT: + scsipi_print_sense = scsipi_print_sense_real; + scsipi_print_sense_data = scsipi_print_sense_data_real; + scsipi_decode_sense = scsipi_decode_sense_real; + return 0; + case MODULE_CMD_FINI: + scsipi_print_sense = scsipi_print_sense_stub; + scsipi_print_sense_data = scsipi_print_sense_data_stub; + scsipi_decode_sense = scsipi_decode_sense_stub; + return 0; + default: + return ENOTTY; + } +} +#else +int (*scsipi_print_sense)(struct scsipi_xfer *, int) = + scsipi_print_sense_real; +void (*scsipi_print_sense_data)(struct scsi_sense_data *, int) = + scsipi_print_sense_data_real; +char *(*scsipi_decode_sense)(void *, int) = scsipi_decode_sense_real; +#endif + static void asc2ascii(u_char asc, u_char ascq, char *result, size_t l) { @@ -620,7 +652,7 @@ } void -scsipi_print_sense_data(struct scsi_sense_data *sense, int verbosity) +scsipi_print_sense_data_real(struct scsi_sense_data *sense, int verbosity) { int32_t info; int i, j, k; @@ -737,7 +769,7 @@ } char * -scsipi_decode_sense(void *sinfo, int flag) +scsipi_decode_sense_real(void *sinfo, int flag) { unsigned char *snsbuf; unsigned char skey; @@ -798,12 +830,13 @@ return (NULL); } -void -scsipi_print_sense(struct scsipi_xfer *xs, int verbosity) +int +scsipi_print_sense_real(struct scsipi_xfer *xs, int verbosity) { scsipi_printaddr(xs->xs_periph); printf(" Check Condition on CDB: "); scsipi_print_cdb(xs->cmd); printf("\n"); scsipi_print_sense_data(&xs->sense.scsi_sense, verbosity); + return 1; } Index: src/sys/dev/scsipi/scsipiconf.c diff -u src/sys/dev/scsipi/scsipiconf.c:1.36 src/sys/dev/scsipi/scsipiconf.c:1.37 --- src/sys/dev/scsipi/scsipiconf.c:1.36 Mon Apr 28 20:23:58 2008 +++ src/sys/dev/scsipi/scsipiconf.c Sun May 30 04:38:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: scsipiconf.c,v 1.36 2008/04/28 20:23:58 martin Exp $ */ +/* $NetBSD: scsipiconf.c,v 1.37 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: scsipiconf.c,v 1.36 2008/04/28 20:23:58 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: scsipiconf.c,v 1.37 2010/05/30 04:38:04 pgoyette Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -62,6 +62,29 @@ #define STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == (u_char)'\377') +/* Function pointers and stub routines for scsiverbose module */ +int (*scsipi_print_sense)(struct scsipi_xfer *, int) = + scsipi_print_sense_stub; +void (*scsipi_print_sense_data)(struct scsi_sense_data *, int) = + scsipi_print_sense_data_stub; +char *(*scsipi_decode_sense)(void *, int) = scsipi_decode_sense_stub; + +int scsipi_print_sense_stub(struct scsipi_xfer * xs, int verbosity) +{ + return 0; +} + +void scsipi_print_sense_data_stub(struct scsi_sense_data *sense, + int verbosity) +{ + return; +} + +char *scsipi_decode_sense_stub(void *sinfo, int flag) +{ + return NULL; +} + int scsipi_command(struct scsipi_periph *periph, struct scsipi_generic *cmd, int cmdlen, u_char *data_addr, int datalen, int retries, int timeout, Index: src/sys/dev/scsipi/scsipiconf.h diff -u src/sys/dev/scsipi/scsipiconf.h:1.116 src/sys/dev/scsipi/scsipiconf.h:1.117 --- src/sys/dev/scsipi/scsipiconf.h:1.116 Wed Oct 21 21:12:05 2009 +++ src/sys/dev/scsipi/scsipiconf.h Sun May 30 04:38:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: scsipiconf.h,v 1.116 2009/10/21 21:12:05 rmind Exp $ */ +/* $NetBSD: scsipiconf.h,v 1.117 2010/05/30 04:38:04 pgoyette Exp $ */ /*- * Copyright (c) 1998, 1999, 2000, 2004 The NetBSD Foundation, Inc. @@ -623,6 +623,7 @@ #ifdef _KERNEL void scsipi_init(void); +void scsipi_verbose_ctl(bool); int scsipi_command(struct scsipi_periph *, struct scsipi_generic *, int, u_char *, int, int, int, struct buf *, int); void scsipi_create_completion_thread(void *); @@ -650,11 +651,16 @@ void scsipi_wait_drain(struct scsipi_periph *); void scsipi_kill_pending(struct scsipi_periph *); struct scsipi_periph *scsipi_alloc_periph(int); -#ifdef SCSIVERBOSE -void scsipi_print_sense(struct scsipi_xfer *, int); -void scsipi_print_sense_data(struct scsi_sense_data *, int); -char *scsipi_decode_sense(void *, int); -#endif + +/* Function pointers for scsiverbose module */ +extern int (*scsipi_print_sense)(struct scsipi_xfer *, int); +extern void (*scsipi_print_sense_data)(struct scsi_sense_data *, int); +extern char *(*scsipi_decode_sense)(void *, int); + +int scsipi_print_sense_stub(struct scsipi_xfer *, int); +void scsipi_print_sense_data_stub(struct scsi_sense_data *, int); +char *scsipi_decode_sense_stub(void *, int); + void scsipi_print_cdb(struct scsipi_generic *cmd); int scsipi_thread_call_callback(struct scsipi_channel *, void (*callback)(struct scsipi_channel *, void *), Index: src/sys/dev/scsipi/st.c diff -u src/sys/dev/scsipi/st.c:1.216 src/sys/dev/scsipi/st.c:1.217 --- src/sys/dev/scsipi/st.c:1.216 Sun Dec 6 22:48:17 2009 +++ src/sys/dev/scsipi/st.c Sun May 30 04:38:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: st.c,v 1.216 2009/12/06 22:48:17 dyoung Exp $ */ +/* $NetBSD: st.c,v 1.217 2010/05/30 04:38:04 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.216 2009/12/06 22:48:17 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.217 2010/05/30 04:38:04 pgoyette Exp $"); #include "opt_scsi.h" @@ -2270,9 +2270,12 @@ doprint = 0; if (doprint) { -#ifdef SCSIVERBOSE - scsipi_print_sense(xs, 0); -#else + + /* Print verbose sense info if possible */ + if (scsipi_print_sense(xs, 0) != 0) + return (retval); + + /* Print less-verbose sense info */ scsipi_printaddr(periph); printf("Sense Key 0x%02x", key); if ((sense->response_code & SSD_RCODE_VALID) != 0) { @@ -2303,7 +2306,6 @@ printf(" %02x", sense->csi[n]); } printf("\n"); -#endif } return (retval); } Index: src/sys/modules/Makefile diff -u src/sys/modules/Makefile:1.43 src/sys/modules/Makefile:1.44 --- src/sys/modules/Makefile:1.43 Sat May 29 01:14:30 2010 +++ src/sys/modules/Makefile Sun May 30 04:38:03 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.43 2010/05/29 01:14:30 pgoyette Exp $ +# $NetBSD: Makefile,v 1.44 2010/05/30 04:38:03 pgoyette Exp $ .include <bsd.own.mk> @@ -45,6 +45,7 @@ SUBDIR+= puffs SUBDIR+= putter SUBDIR+= miniroot +SUBDIR+= scsiverbose SUBDIR+= secmodel_bsd44 SUBDIR+= secmodel_overlay SUBDIR+= securelevel Added files: Index: src/sys/modules/scsiverbose/Makefile diff -u /dev/null src/sys/modules/scsiverbose/Makefile:1.1 --- /dev/null Sun May 30 04:38:04 2010 +++ src/sys/modules/scsiverbose/Makefile Sun May 30 04:38:03 2010 @@ -0,0 +1,10 @@ +# $NetBSD: Makefile,v 1.1 2010/05/30 04:38:03 pgoyette Exp $ + +.include "../Makefile.inc" + +KMOD= scsiverbose + +.PATH: ${S}/dev/scsipi +SRCS= scsipi_verbose.c + +.include <bsd.kmodule.mk>