2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2000 Matthew Jacob
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * This file contains definitions only intended for use within
33 * sys/cam/scsi/scsi_enc*.c, and not in other kernel components.
36 #ifndef __SCSI_ENC_INTERNAL_H__
37 #define __SCSI_ENC_INTERNAL_H__
39 typedef struct enc_element {
41 enctype : 8, /* enclosure type */
42 subenclosure : 8, /* subenclosure id */
43 svalid : 1, /* enclosure information valid */
44 overall_status_elem: 1,/*
45 * This object represents generic
46 * status about all objects of this
49 priv : 14; /* private data, per object */
50 uint8_t encstat[4]; /* state && stats */
51 uint8_t *physical_path; /* Device physical path data. */
52 u_int physical_path_len; /* Length of device path data. */
53 void *elm_private; /* per-type object data */
67 /* Platform Independent Driver Internal Definitions for enclosure devices. */
68 typedef struct enc_softc enc_softc_t;
71 typedef int fsm_fill_handler_t(enc_softc_t *ssc,
72 struct enc_fsm_state *state,
75 typedef int fsm_error_handler_t(union ccb *ccb, uint32_t cflags,
77 typedef int fsm_done_handler_t(enc_softc_t *ssc,
78 struct enc_fsm_state *state, union ccb *ccb,
79 uint8_t **bufp, int error, int xfer_len);
81 struct enc_fsm_state {
86 fsm_fill_handler_t *fill;
87 fsm_done_handler_t *done;
88 fsm_error_handler_t *error;
91 typedef int (enc_softc_init_t)(enc_softc_t *);
92 typedef void (enc_softc_invalidate_t)(enc_softc_t *);
93 typedef void (enc_softc_cleanup_t)(enc_softc_t *);
94 typedef int (enc_init_enc_t)(enc_softc_t *);
95 typedef int (enc_get_enc_status_t)(enc_softc_t *, int);
96 typedef int (enc_set_enc_status_t)(enc_softc_t *, encioc_enc_status_t, int);
97 typedef int (enc_get_elm_status_t)(enc_softc_t *, encioc_elm_status_t *, int);
98 typedef int (enc_set_elm_status_t)(enc_softc_t *, encioc_elm_status_t *, int);
99 typedef int (enc_get_elm_desc_t)(enc_softc_t *, encioc_elm_desc_t *);
100 typedef int (enc_get_elm_devnames_t)(enc_softc_t *, encioc_elm_devnames_t *);
101 typedef int (enc_handle_string_t)(enc_softc_t *, encioc_string_t *, int);
102 typedef void (enc_device_found_t)(enc_softc_t *);
103 typedef void (enc_poll_status_t)(enc_softc_t *);
106 enc_softc_invalidate_t *softc_invalidate;
107 enc_softc_cleanup_t *softc_cleanup;
108 enc_init_enc_t *init_enc;
109 enc_get_enc_status_t *get_enc_status;
110 enc_set_enc_status_t *set_enc_status;
111 enc_get_elm_status_t *get_elm_status;
112 enc_set_elm_status_t *set_elm_status;
113 enc_get_elm_desc_t *get_elm_desc;
114 enc_get_elm_devnames_t *get_elm_devnames;
115 enc_handle_string_t *handle_string;
116 enc_device_found_t *device_found;
117 enc_poll_status_t *poll_status;
120 typedef struct enc_cache {
121 enc_element_t *elm_map; /* objects */
122 int nelms; /* number of objects */
123 encioc_enc_status_t enc_status; /* overall status */
124 void *private; /* per-type private data */
127 /* Enclosure instance toplevel structure */
129 enctyp enc_type; /* type of enclosure */
130 struct enc_vec enc_vec; /* vector to handlers */
131 void *enc_private; /* per-type private data */
134 * "Published" configuration and state data available to
135 * external consumers.
137 enc_cache_t enc_cache;
140 * Configuration and state data being actively updated
141 * by the enclosure daemon.
143 enc_cache_t enc_daemon_cache;
145 struct sx enc_cache_lock;
147 #define ENC_FLAG_INVALID 0x01
148 #define ENC_FLAG_INITIALIZED 0x02
149 #define ENC_FLAG_SHUTDOWN 0x04
151 struct cdev *enc_dev;
152 struct cam_periph *periph;
155 /* Bitmap of pending operations. */
156 uint32_t pending_actions;
158 /* The action on which the state machine is currently working. */
159 uint32_t current_action;
160 #define ENC_UPDATE_NONE 0x00
161 #define ENC_UPDATE_INVALID 0xff
163 /* Callout for auto-updating enclosure status */
164 struct callout status_updater;
166 struct proc *enc_daemon;
168 struct enc_fsm_state *enc_fsm_states;
170 struct intr_config_hook enc_boot_hold_ch;
172 #define ENC_ANNOUNCE_SZ 400
173 char announce_buf[ENC_ANNOUNCE_SZ];
176 static inline enc_cache_t *
177 enc_other_cache(enc_softc_t *enc, enc_cache_t *primary)
179 return (primary == &enc->enc_cache
180 ? &enc->enc_daemon_cache : &enc->enc_cache);
183 /* SES Management mode page - SES2r20 Table 59 */
184 struct ses_mgmt_mode_page {
185 struct scsi_mode_header_6 header;
186 struct scsi_mode_blk_desc blk_desc;
187 uint8_t byte0; /* ps : 1, spf : 1, page_code : 6 */
188 #define SES_MGMT_MODE_PAGE_CODE 0x14
190 #define SES_MGMT_MODE_PAGE_LEN 6
192 uint8_t byte5; /* reserved : 7, enbltc : 1 */
193 #define SES_MGMT_TIMED_COMP_EN 0x1
194 uint8_t max_comp_time[2];
197 /* Enclosure core interface for sub-drivers */
198 int enc_runcmd(struct enc_softc *, char *, int, char *, int *);
199 void enc_log(struct enc_softc *, const char *, ...);
200 int enc_error(union ccb *, uint32_t, uint32_t);
201 void enc_update_request(enc_softc_t *, uint32_t);
203 /* SES Native interface */
204 enc_softc_init_t ses_softc_init;
206 /* SAF-TE interface */
207 enc_softc_init_t safte_softc_init;
210 MALLOC_DECLARE(M_SCSIENC);
211 #define ENC_CFLAGS CAM_RETRY_SELTO
212 #define ENC_FLAGS SF_NO_PRINT | SF_RETRY_UA
213 #define STRNCMP strncmp
214 #define PRINTF printf
215 #define ENC_LOG enc_log
216 #if defined(DEBUG) || defined(ENC_DEBUG)
217 #define ENC_DLOG enc_log
219 #define ENC_DLOG if (0) enc_log
221 #define ENC_VLOG if (bootverbose) enc_log
222 #define ENC_MALLOC(amt) malloc(amt, M_SCSIENC, M_NOWAIT)
223 #define ENC_MALLOCZ(amt) malloc(amt, M_SCSIENC, M_ZERO|M_NOWAIT)
224 /* Cast away const avoiding GCC warnings. */
225 #define ENC_FREE(ptr) free((void *)((uintptr_t)ptr), M_SCSIENC)
226 #define ENC_FREE_AND_NULL(ptr) do { \
232 #define MEMZERO bzero
233 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
235 #endif /* __SCSI_ENC_INTERNAL_H__ */