xref: /freebsd/sys/cam/scsi/scsi_enc.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /*-
2  * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
3  *
4  * Copyright (c) 2000 by Matthew Jacob
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer,
12  *    without modification, immediately at the beginning of the file.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * Alternatively, this software may be distributed under the terms of the
17  * the GNU Public License ("GPL").
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  */
32 #ifndef	_SCSI_ENC_H_
33 #define	_SCSI_ENC_H_
34 
35 #include <cam/scsi/scsi_ses.h>
36 
37 #define	ENCIOC			('s' - 040)
38 #define	ENCIOC_GETNELM		_IO(ENCIOC, 1)
39 #define	ENCIOC_GETELMMAP	_IO(ENCIOC, 2)
40 #define	ENCIOC_GETENCSTAT	_IO(ENCIOC, 3)
41 #define	ENCIOC_SETENCSTAT	_IO(ENCIOC, 4)
42 #define	ENCIOC_GETELMSTAT	_IO(ENCIOC, 5)
43 #define	ENCIOC_SETELMSTAT	_IO(ENCIOC, 6)
44 #define	ENCIOC_GETTEXT		_IO(ENCIOC, 7)
45 #define	ENCIOC_INIT		_IO(ENCIOC, 8)
46 #define	ENCIOC_GETELMDESC	_IO(ENCIOC, 9)
47 #define	ENCIOC_GETELMDEVNAMES	_IO(ENCIOC, 10)
48 #define	ENCIOC_GETSTRING	_IO(ENCIOC, 11)
49 #define	ENCIOC_SETSTRING	_IO(ENCIOC, 12)
50 #define	ENCIOC_GETENCNAME	_IO(ENCIOC, 13)
51 #define	ENCIOC_GETENCID		_IO(ENCIOC, 14)
52 
53 /*
54  * Platform Independent Definitions for enclosure devices.
55  */
56 /*
57  * SCSI Based Environmental Services Application Defines
58  *
59  * Based almost entirely on SCSI-3 ENC Revision 8A specification,
60  * but slightly abstracted as the underlying device may in fact
61  * be a SAF-TE or vendor unique device.
62  */
63 /*
64  * ENC Driver Operations:
65  * (The defines themselves are platform and access method specific)
66  *
67  * ENCIOC_GETNELM
68  * ENCIOC_GETELMMAP
69  * ENCIOC_GETENCSTAT
70  * ENCIOC_SETENCSTAT
71  * ENCIOC_GETELMSTAT
72  * ENCIOC_SETELMSTAT
73  * ENCIOC_INIT
74  *
75  *
76  * An application finds out how many elements an enclosure instance
77  * manages by performing a ENCIOC_GETNELM operation. It then
78  * performs an ENCIOC_GETELMMAP to get the map that contains the
79  * element identifiers for all elements (see encioc_element_t below).
80  * This information is static.
81  *
82  * The application may perform ENCIOC_GETELMSTAT operations to retrieve
83  * status on an element (see the encioc_elm_status_t structure below),
84  * and ENCIOC_SETELMSTAT operations to set status for an element.
85  *
86  * Similarly, overall enclosure status may be fetched or set via
87  * ENCIOC_GETENCSTAT or ENCIOC_SETENCSTAT operations (see encioc_enc_status_t
88  * below).
89  *
90  * Readers should note that there is nothing that requires either a set
91  * or a clear operation to actually latch and do anything in the target.
92  *
93  * An ENCIOC_INIT operation causes the enclosure to be initialized.
94  */
95 
96 /* Element Types */
97 typedef enum {
98 	ELMTYP_UNSPECIFIED	= 0x00,
99 	ELMTYP_DEVICE		= 0x01,
100 	ELMTYP_POWER		= 0x02,
101 	ELMTYP_FAN		= 0x03,
102 	ELMTYP_THERM		= 0x04,
103 	ELMTYP_DOORLOCK		= 0x05,
104 	ELMTYP_ALARM		= 0x06,
105 	ELMTYP_ESCC		= 0x07,	/* Enclosure SCC */
106 	ELMTYP_SCC		= 0x08,	/* SCC */
107 	ELMTYP_NVRAM		= 0x09,
108 	ELMTYP_INV_OP_REASON    = 0x0a,
109 	ELMTYP_UPS		= 0x0b,
110 	ELMTYP_DISPLAY		= 0x0c,
111 	ELMTYP_KEYPAD		= 0x0d,
112 	ELMTYP_ENCLOSURE	= 0x0e,
113 	ELMTYP_SCSIXVR		= 0x0f,
114 	ELMTYP_LANGUAGE		= 0x10,
115 	ELMTYP_COMPORT		= 0x11,
116 	ELMTYP_VOM		= 0x12,
117 	ELMTYP_AMMETER		= 0x13,
118 	ELMTYP_SCSI_TGT		= 0x14,
119 	ELMTYP_SCSI_INI		= 0x15,
120 	ELMTYP_SUBENC		= 0x16,
121 	ELMTYP_ARRAY_DEV	= 0x17,
122 	ELMTYP_SAS_EXP		= 0x18,	/* SAS Expander */
123 	ELMTYP_SAS_CONN		= 0x19,	/* SAS Connector */
124 	ELMTYP_LAST		= ELMTYP_SAS_CONN
125 } elm_type_t;
126 
127 #define	ELM_TYPE_NAMES	{				\
128 	"Unspecified",					\
129 	"Device Slot",					\
130 	"Power Supply",					\
131 	"Cooling",					\
132 	"Temperature Sensor",				\
133 	"Door",						\
134 	"Audible alarm",				\
135 	"Enclosure Services Controller Electronics",	\
136 	"SCC Controller Electronics",			\
137 	"Nonvolatile Cache",				\
138 	"Invalid Operation Reason",			\
139 	"Uninterruptible Power Supply",			\
140 	"Display",					\
141 	"Key Pad Entry",				\
142 	"Enclosure",					\
143 	"SCSI Port/Transceiver",			\
144 	"Language",					\
145 	"Communication Port",				\
146 	"Voltage Sensor",				\
147 	"Current Sensor",				\
148 	"SCSI Target Port",				\
149 	"SCSI Initiator Port",				\
150 	"Simple Subenclosure",				\
151 	"Array Device Slot",				\
152 	"SAS Expander",					\
153 	"SAS Connector"					\
154 }
155 
156 #ifdef _KERNEL
157 extern const char *elm_type_names[];
158 #endif
159 
160 typedef struct encioc_element {
161 	/* Element Index */
162 	unsigned int	elm_idx;
163 
164 	/* ID of SubEnclosure containing Element*/
165 	unsigned int	elm_subenc_id;
166 
167 	/* Element Type */
168 	elm_type_t	elm_type;
169 } encioc_element_t;
170 
171 /*
172  * Overall Enclosure Status
173  */
174 typedef unsigned char encioc_enc_status_t;
175 
176 /*
177  * Element Status
178  */
179 typedef struct encioc_elm_status {
180 	unsigned int	elm_idx;
181 	unsigned char	cstat[4];
182 } encioc_elm_status_t;
183 
184 /*
185  * ENC String structure, for StringIn and StringOut commands; use this with
186  * the ENCIOC_GETSTRING and ENCIOC_SETSTRING ioctls.
187  */
188 typedef struct encioc_string {
189 	size_t bufsiz;		/* IN/OUT: length of string provided/returned */
190 #define	ENC_STRING_MAX	0xffff
191 	uint8_t *buf;		/* IN/OUT: string */
192 } encioc_string_t;
193 
194 /*============================================================================*/
195 
196 /*
197  * SES v2 r20 6.1.10 (pg 39) - Element Descriptor diagnostic page
198  * Tables 21, 22, and 23
199  */
200 typedef struct encioc_elm_desc {
201 	unsigned int	 elm_idx;       /* IN: elment requested */
202 	uint16_t	 elm_desc_len; /* IN: buffer size; OUT: bytes written */
203 	char		*elm_desc_str; /* IN/OUT: buffer for descriptor data */
204 } encioc_elm_desc_t;
205 
206 /*
207  * ENCIOC_GETELMDEVNAMES:
208  * ioctl structure to get an element's device names, if available
209  */
210 typedef struct  encioc_elm_devnames {
211 	unsigned int	 elm_idx;	/* IN: element index */
212 	size_t		 elm_names_size;/* IN: size of elm_devnames */
213 	size_t		 elm_names_len;	/* OUT: actual size returned */
214 	/*
215 	 * IN/OUT: comma separated list of peripheral driver
216 	 * instances servicing this element.
217 	 */
218 	char		*elm_devnames;
219 } encioc_elm_devnames_t;
220 
221 /* ioctl structure for requesting FC info for a port */
222 typedef struct encioc_elm_fc_port {
223 	unsigned int		elm_idx;
224 	unsigned int		port_idx;
225 	struct ses_elm_fc_port	port_data;
226 } encioc_elm_fc_port_t;
227 
228 /* ioctl structure for requesting SAS info for element phys */
229 typedef struct encioc_elm_sas_device_phy {
230 	unsigned int			elm_idx;
231 	unsigned int			phy_idx;
232 	struct ses_elm_sas_device_phy	phy_data;
233 } enioc_elm_sas_phy_t;
234 
235 /* ioctl structure for requesting SAS info for an expander phy */
236 typedef struct encioc_elm_sas_expander_phy {
237 	unsigned int			elm_idx;
238 	unsigned int			phy_idx;
239 	struct ses_elm_sas_expander_phy phy_data;
240 } encioc_elm_sas_expander_phy_t;
241 
242 /* ioctl structure for requesting SAS info for a port phy */
243 typedef struct encioc_elm_sas_port_phy {
244 	unsigned int			elm_idx;
245 	unsigned int			phy_idx;
246 	struct ses_elm_sas_port_phy	phy_data;
247 } enioc_elm_sas_port_phy_t;
248 
249 /* ioctl structure for requesting additional status for an element */
250 typedef struct encioc_addl_status {
251 	unsigned int			   elm_idx;
252 	union ses_elm_addlstatus_descr_hdr addl_hdr;
253 	union ses_elm_addlstatus_proto_hdr proto_hdr;
254 } enioc_addl_status_t;
255 
256 #endif /* _SCSI_ENC_H_ */
257