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