xref: /netbsd-src/sys/dev/scsipi/scsi_subr.c (revision 9dda5c7f82626a01f0be585fb54fae9d9630b47c)
1 /*	$NetBSD: scsi_subr.c,v 1.1 2022/04/14 16:50:26 pgoyette Exp $ */
2 
3 /*-
4  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
9  * Simulation Facility, NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * Originally written by Julian Elischer (julian@tfs.com)
35  * for TRW Financial Systems for use under the MACH(2.5) operating system.
36  *
37  * TRW Financial Systems, in accordance with their agreement with Carnegie
38  * Mellon University, makes this software available to CMU to distribute
39  * or use in any manner that they see fit as long as this message is kept with
40  * the software. For this reason TFS also grants any other persons or
41  * organisations permission to use or modify this software.
42  *
43  * TFS supplies this software to be publicly redistributed
44  * on the understanding that TFS is not responsible for the correct
45  * functioning of this software in any circumstances.
46  *
47  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
48  */
49 
50 #include <sys/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: scsi_subr.c,v 1.1 2022/04/14 16:50:26 pgoyette Exp $");
52 
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 
56 #include <sys/device.h>
57 #include <sys/kernel.h>
58 #include <sys/proc.h>
59 #include <sys/module.h>
60 
61 #include <dev/scsipi/scsi_all.h>
62 #include <dev/scsipi/scsipi_all.h>
63 #include <dev/scsipi/scsiconf.h>
64 
65 const struct scsipi_bustype scsi_bustype = {
66 	.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
67 	    SCSIPI_BUSTYPE_SCSI_PSCSI),
68 	.bustype_cmd = scsi_scsipi_cmd,
69 	.bustype_interpret_sense = scsipi_interpret_sense,
70 	.bustype_printaddr = scsi_print_addr,
71 	.bustype_kill_pending = scsi_kill_pending,
72 	.bustype_async_event_xfer_mode = scsi_async_event_xfer_mode,
73 };
74 
75 const struct scsipi_bustype scsi_fc_bustype = {
76 	.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
77 	    SCSIPI_BUSTYPE_SCSI_FC),
78 	.bustype_cmd = scsi_scsipi_cmd,
79 	.bustype_interpret_sense = scsipi_interpret_sense,
80 	.bustype_printaddr = scsi_print_addr,
81 	.bustype_kill_pending = scsi_kill_pending,
82 	.bustype_async_event_xfer_mode = scsi_fc_sas_async_event_xfer_mode,
83 };
84 
85 const struct scsipi_bustype scsi_sas_bustype = {
86 	.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
87 	    SCSIPI_BUSTYPE_SCSI_SAS),
88 	.bustype_cmd = scsi_scsipi_cmd,
89 	.bustype_interpret_sense = scsipi_interpret_sense,
90 	.bustype_printaddr = scsi_print_addr,
91 	.bustype_kill_pending = scsi_kill_pending,
92 	.bustype_async_event_xfer_mode = scsi_fc_sas_async_event_xfer_mode,
93 };
94 
95 const struct scsipi_bustype scsi_usb_bustype = {
96 	.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
97 	    SCSIPI_BUSTYPE_SCSI_USB),
98 	.bustype_cmd = scsi_scsipi_cmd,
99 	.bustype_interpret_sense = scsipi_interpret_sense,
100 	.bustype_printaddr = scsi_print_addr,
101 	.bustype_kill_pending = scsi_kill_pending,
102 	.bustype_async_event_xfer_mode = NULL,
103 };
104 
105 int
scsiprint(void * aux,const char * pnp)106 scsiprint(void *aux, const char *pnp)
107 {
108 	struct scsipi_channel *chan = aux;
109 	struct scsipi_adapter *adapt = chan->chan_adapter;
110 
111 	/* only "scsibus"es can attach to "scsi"s; easy. */
112 	if (pnp)
113 		aprint_normal("scsibus at %s", pnp);
114 
115 	/* don't print channel if the controller says there can be only one. */
116 	if (adapt->adapt_nchannels != 1)
117 		aprint_normal(" channel %d", chan->chan_channel);
118 
119 	return (UNCONF);
120 }
121 
122 MODULE(MODULE_CLASS_EXEC, scsi_subr, NULL);
123 
scsi_subr_modcmd(modcmd_t cmd,void * opaque)124 static int scsi_subr_modcmd(modcmd_t cmd, void *opaque)
125 {
126 
127 	switch(cmd) {
128 	case MODULE_CMD_INIT:
129 	case MODULE_CMD_FINI:
130 		return 0;
131 	default:
132 		return ENOTTY;
133 	}
134 }
135