1f6ad3f23SAlexander Motin /*- 2bec9534dSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3bec9534dSPedro F. Giffuni * 4f6ad3f23SAlexander Motin * Copyright (c) 2000 Matthew Jacob 5f6ad3f23SAlexander Motin * All rights reserved. 6f6ad3f23SAlexander Motin * 7f6ad3f23SAlexander Motin * Redistribution and use in source and binary forms, with or without 8f6ad3f23SAlexander Motin * modification, are permitted provided that the following conditions 9f6ad3f23SAlexander Motin * are met: 10f6ad3f23SAlexander Motin * 1. Redistributions of source code must retain the above copyright 11f6ad3f23SAlexander Motin * notice, this list of conditions, and the following disclaimer, 12f6ad3f23SAlexander Motin * without modification, immediately at the beginning of the file. 13f6ad3f23SAlexander Motin * 2. The name of the author may not be used to endorse or promote products 14f6ad3f23SAlexander Motin * derived from this software without specific prior written permission. 15f6ad3f23SAlexander Motin * 16f6ad3f23SAlexander Motin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17f6ad3f23SAlexander Motin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18f6ad3f23SAlexander Motin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19f6ad3f23SAlexander Motin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20f6ad3f23SAlexander Motin * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21f6ad3f23SAlexander Motin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22f6ad3f23SAlexander Motin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23f6ad3f23SAlexander Motin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24f6ad3f23SAlexander Motin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25f6ad3f23SAlexander Motin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26f6ad3f23SAlexander Motin * SUCH DAMAGE. 27f6ad3f23SAlexander Motin * 28f6ad3f23SAlexander Motin * $FreeBSD$ 29f6ad3f23SAlexander Motin */ 30f6ad3f23SAlexander Motin 31f6ad3f23SAlexander Motin /* 32f6ad3f23SAlexander Motin * This file contains definitions only intended for use within 33f6ad3f23SAlexander Motin * sys/cam/scsi/scsi_enc*.c, and not in other kernel components. 34f6ad3f23SAlexander Motin */ 35f6ad3f23SAlexander Motin 36f6ad3f23SAlexander Motin #ifndef __SCSI_ENC_INTERNAL_H__ 37f6ad3f23SAlexander Motin #define __SCSI_ENC_INTERNAL_H__ 38f6ad3f23SAlexander Motin 396d4d6573SAlexander Motin #include <sys/sysctl.h> 406d4d6573SAlexander Motin 41f6ad3f23SAlexander Motin typedef struct enc_element { 42f6ad3f23SAlexander Motin uint32_t 43f6ad3f23SAlexander Motin enctype : 8, /* enclosure type */ 44f6ad3f23SAlexander Motin subenclosure : 8, /* subenclosure id */ 45f6ad3f23SAlexander Motin svalid : 1, /* enclosure information valid */ 46f6ad3f23SAlexander Motin overall_status_elem: 1,/* 47f6ad3f23SAlexander Motin * This object represents generic 48f6ad3f23SAlexander Motin * status about all objects of this 49f6ad3f23SAlexander Motin * type. 50f6ad3f23SAlexander Motin */ 51f6ad3f23SAlexander Motin priv : 14; /* private data, per object */ 52f6ad3f23SAlexander Motin uint8_t encstat[4]; /* state && stats */ 53f6ad3f23SAlexander Motin uint8_t *physical_path; /* Device physical path data. */ 54f6ad3f23SAlexander Motin u_int physical_path_len; /* Length of device path data. */ 55f6ad3f23SAlexander Motin void *elm_private; /* per-type object data */ 56f6ad3f23SAlexander Motin } enc_element_t; 57f6ad3f23SAlexander Motin 58f6ad3f23SAlexander Motin typedef enum { 59f6ad3f23SAlexander Motin ENC_NONE, 60f6ad3f23SAlexander Motin ENC_SES, 61f6ad3f23SAlexander Motin ENC_SES_PASSTHROUGH, 62f6ad3f23SAlexander Motin ENC_SAFT, 63f6ad3f23SAlexander Motin ENC_SEMB_SES, 64f6ad3f23SAlexander Motin ENC_SEMB_SAFT 65f6ad3f23SAlexander Motin } enctyp; 66f6ad3f23SAlexander Motin 67f6ad3f23SAlexander Motin /* Platform Independent Driver Internal Definitions for enclosure devices. */ 68f6ad3f23SAlexander Motin typedef struct enc_softc enc_softc_t; 69f6ad3f23SAlexander Motin 70f6ad3f23SAlexander Motin struct enc_fsm_state; 71f6ad3f23SAlexander Motin typedef int fsm_fill_handler_t(enc_softc_t *ssc, 72f6ad3f23SAlexander Motin struct enc_fsm_state *state, 73f6ad3f23SAlexander Motin union ccb *ccb, 74f6ad3f23SAlexander Motin uint8_t *buf); 75f6ad3f23SAlexander Motin typedef int fsm_error_handler_t(union ccb *ccb, uint32_t cflags, 76f6ad3f23SAlexander Motin uint32_t sflags); 77f6ad3f23SAlexander Motin typedef int fsm_done_handler_t(enc_softc_t *ssc, 78f6ad3f23SAlexander Motin struct enc_fsm_state *state, union ccb *ccb, 79f6ad3f23SAlexander Motin uint8_t **bufp, int error, int xfer_len); 80f6ad3f23SAlexander Motin 81f6ad3f23SAlexander Motin struct enc_fsm_state { 82f6ad3f23SAlexander Motin const char *name; 83f6ad3f23SAlexander Motin int page_code; 84f6ad3f23SAlexander Motin size_t buf_size; 85f6ad3f23SAlexander Motin uint32_t timeout; 86f6ad3f23SAlexander Motin fsm_fill_handler_t *fill; 87f6ad3f23SAlexander Motin fsm_done_handler_t *done; 88f6ad3f23SAlexander Motin fsm_error_handler_t *error; 89f6ad3f23SAlexander Motin }; 90f6ad3f23SAlexander Motin 91f6ad3f23SAlexander Motin typedef int (enc_softc_init_t)(enc_softc_t *); 92f6ad3f23SAlexander Motin typedef void (enc_softc_invalidate_t)(enc_softc_t *); 93f6ad3f23SAlexander Motin typedef void (enc_softc_cleanup_t)(enc_softc_t *); 94f6ad3f23SAlexander Motin typedef int (enc_init_enc_t)(enc_softc_t *); 95f6ad3f23SAlexander Motin typedef int (enc_get_enc_status_t)(enc_softc_t *, int); 96f6ad3f23SAlexander Motin typedef int (enc_set_enc_status_t)(enc_softc_t *, encioc_enc_status_t, int); 97f6ad3f23SAlexander Motin typedef int (enc_get_elm_status_t)(enc_softc_t *, encioc_elm_status_t *, int); 98f6ad3f23SAlexander Motin typedef int (enc_set_elm_status_t)(enc_softc_t *, encioc_elm_status_t *, int); 99f6ad3f23SAlexander Motin typedef int (enc_get_elm_desc_t)(enc_softc_t *, encioc_elm_desc_t *); 100f6ad3f23SAlexander Motin typedef int (enc_get_elm_devnames_t)(enc_softc_t *, encioc_elm_devnames_t *); 101f6ad3f23SAlexander Motin typedef int (enc_handle_string_t)(enc_softc_t *, encioc_string_t *, int); 102f6ad3f23SAlexander Motin typedef void (enc_device_found_t)(enc_softc_t *); 103f6ad3f23SAlexander Motin typedef void (enc_poll_status_t)(enc_softc_t *); 104f6ad3f23SAlexander Motin 105f6ad3f23SAlexander Motin struct enc_vec { 106f6ad3f23SAlexander Motin enc_softc_invalidate_t *softc_invalidate; 107f6ad3f23SAlexander Motin enc_softc_cleanup_t *softc_cleanup; 108f6ad3f23SAlexander Motin enc_init_enc_t *init_enc; 109f6ad3f23SAlexander Motin enc_get_enc_status_t *get_enc_status; 110f6ad3f23SAlexander Motin enc_set_enc_status_t *set_enc_status; 111f6ad3f23SAlexander Motin enc_get_elm_status_t *get_elm_status; 112f6ad3f23SAlexander Motin enc_set_elm_status_t *set_elm_status; 113f6ad3f23SAlexander Motin enc_get_elm_desc_t *get_elm_desc; 114f6ad3f23SAlexander Motin enc_get_elm_devnames_t *get_elm_devnames; 115f6ad3f23SAlexander Motin enc_handle_string_t *handle_string; 116f6ad3f23SAlexander Motin enc_device_found_t *device_found; 117f6ad3f23SAlexander Motin enc_poll_status_t *poll_status; 118f6ad3f23SAlexander Motin }; 119f6ad3f23SAlexander Motin 120f6ad3f23SAlexander Motin typedef struct enc_cache { 121f6ad3f23SAlexander Motin enc_element_t *elm_map; /* objects */ 122f6ad3f23SAlexander Motin int nelms; /* number of objects */ 123f6ad3f23SAlexander Motin encioc_enc_status_t enc_status; /* overall status */ 124f6ad3f23SAlexander Motin void *private; /* per-type private data */ 125f6ad3f23SAlexander Motin } enc_cache_t; 126f6ad3f23SAlexander Motin 127f6ad3f23SAlexander Motin /* Enclosure instance toplevel structure */ 128f6ad3f23SAlexander Motin struct enc_softc { 129f6ad3f23SAlexander Motin enctyp enc_type; /* type of enclosure */ 130f6ad3f23SAlexander Motin struct enc_vec enc_vec; /* vector to handlers */ 131f6ad3f23SAlexander Motin void *enc_private; /* per-type private data */ 132f6ad3f23SAlexander Motin 133f6ad3f23SAlexander Motin /** 134f6ad3f23SAlexander Motin * "Published" configuration and state data available to 135f6ad3f23SAlexander Motin * external consumers. 136f6ad3f23SAlexander Motin */ 137f6ad3f23SAlexander Motin enc_cache_t enc_cache; 138f6ad3f23SAlexander Motin 139f6ad3f23SAlexander Motin /** 140f6ad3f23SAlexander Motin * Configuration and state data being actively updated 141f6ad3f23SAlexander Motin * by the enclosure daemon. 142f6ad3f23SAlexander Motin */ 143f6ad3f23SAlexander Motin enc_cache_t enc_daemon_cache; 144f6ad3f23SAlexander Motin 145f6ad3f23SAlexander Motin struct sx enc_cache_lock; 146f6ad3f23SAlexander Motin uint8_t enc_flags; 147f6ad3f23SAlexander Motin #define ENC_FLAG_INVALID 0x01 148f6ad3f23SAlexander Motin #define ENC_FLAG_INITIALIZED 0x02 149f6ad3f23SAlexander Motin #define ENC_FLAG_SHUTDOWN 0x04 150f6ad3f23SAlexander Motin union ccb saved_ccb; 151f6ad3f23SAlexander Motin struct cdev *enc_dev; 152f6ad3f23SAlexander Motin struct cam_periph *periph; 15386d45c7fSKenneth D. Merry int open_count; 154f6ad3f23SAlexander Motin 155f6ad3f23SAlexander Motin /* Bitmap of pending operations. */ 156f6ad3f23SAlexander Motin uint32_t pending_actions; 157f6ad3f23SAlexander Motin 158f6ad3f23SAlexander Motin /* The action on which the state machine is currently working. */ 159f6ad3f23SAlexander Motin uint32_t current_action; 160f6ad3f23SAlexander Motin #define ENC_UPDATE_NONE 0x00 161f6ad3f23SAlexander Motin #define ENC_UPDATE_INVALID 0xff 162f6ad3f23SAlexander Motin 163f6ad3f23SAlexander Motin /* Callout for auto-updating enclosure status */ 164f6ad3f23SAlexander Motin struct callout status_updater; 165f6ad3f23SAlexander Motin 166f6ad3f23SAlexander Motin struct proc *enc_daemon; 167f6ad3f23SAlexander Motin 168f6ad3f23SAlexander Motin struct enc_fsm_state *enc_fsm_states; 169f6ad3f23SAlexander Motin 170f6ad3f23SAlexander Motin struct intr_config_hook enc_boot_hold_ch; 1715d01277fSScott Long 1725d01277fSScott Long #define ENC_ANNOUNCE_SZ 400 1735d01277fSScott Long char announce_buf[ENC_ANNOUNCE_SZ]; 174f6ad3f23SAlexander Motin }; 175f6ad3f23SAlexander Motin 176f6ad3f23SAlexander Motin static inline enc_cache_t * 177f6ad3f23SAlexander Motin enc_other_cache(enc_softc_t *enc, enc_cache_t *primary) 178f6ad3f23SAlexander Motin { 179f6ad3f23SAlexander Motin return (primary == &enc->enc_cache 180f6ad3f23SAlexander Motin ? &enc->enc_daemon_cache : &enc->enc_cache); 181f6ad3f23SAlexander Motin } 182f6ad3f23SAlexander Motin 183f6ad3f23SAlexander Motin /* SES Management mode page - SES2r20 Table 59 */ 184f6ad3f23SAlexander Motin struct ses_mgmt_mode_page { 185f6ad3f23SAlexander Motin struct scsi_mode_header_6 header; 186f6ad3f23SAlexander Motin struct scsi_mode_blk_desc blk_desc; 187f6ad3f23SAlexander Motin uint8_t byte0; /* ps : 1, spf : 1, page_code : 6 */ 188f6ad3f23SAlexander Motin #define SES_MGMT_MODE_PAGE_CODE 0x14 189f6ad3f23SAlexander Motin uint8_t length; 190f6ad3f23SAlexander Motin #define SES_MGMT_MODE_PAGE_LEN 6 191f6ad3f23SAlexander Motin uint8_t reserved[3]; 192f6ad3f23SAlexander Motin uint8_t byte5; /* reserved : 7, enbltc : 1 */ 193f6ad3f23SAlexander Motin #define SES_MGMT_TIMED_COMP_EN 0x1 194f6ad3f23SAlexander Motin uint8_t max_comp_time[2]; 195f6ad3f23SAlexander Motin }; 196f6ad3f23SAlexander Motin 197f6ad3f23SAlexander Motin /* Enclosure core interface for sub-drivers */ 198f6ad3f23SAlexander Motin int enc_runcmd(struct enc_softc *, char *, int, char *, int *); 199f6ad3f23SAlexander Motin void enc_log(struct enc_softc *, const char *, ...); 200f6ad3f23SAlexander Motin int enc_error(union ccb *, uint32_t, uint32_t); 201f6ad3f23SAlexander Motin void enc_update_request(enc_softc_t *, uint32_t); 202f6ad3f23SAlexander Motin 203f6ad3f23SAlexander Motin /* SES Native interface */ 204f6ad3f23SAlexander Motin enc_softc_init_t ses_softc_init; 205f6ad3f23SAlexander Motin 206f6ad3f23SAlexander Motin /* SAF-TE interface */ 207f6ad3f23SAlexander Motin enc_softc_init_t safte_softc_init; 208f6ad3f23SAlexander Motin 2096d4d6573SAlexander Motin SYSCTL_DECL(_kern_cam_enc); 2106d4d6573SAlexander Motin extern int enc_verbose; 2116d4d6573SAlexander Motin 212f6ad3f23SAlexander Motin /* Helper macros */ 213f6ad3f23SAlexander Motin MALLOC_DECLARE(M_SCSIENC); 214f6ad3f23SAlexander Motin #define ENC_CFLAGS CAM_RETRY_SELTO 215f6ad3f23SAlexander Motin #define ENC_FLAGS SF_NO_PRINT | SF_RETRY_UA 216f6ad3f23SAlexander Motin #define STRNCMP strncmp 217f6ad3f23SAlexander Motin #define PRINTF printf 218f6ad3f23SAlexander Motin #define ENC_LOG enc_log 219f6ad3f23SAlexander Motin #if defined(DEBUG) || defined(ENC_DEBUG) 220f6ad3f23SAlexander Motin #define ENC_DLOG enc_log 221f6ad3f23SAlexander Motin #else 222f6ad3f23SAlexander Motin #define ENC_DLOG if (0) enc_log 223f6ad3f23SAlexander Motin #endif 2246d4d6573SAlexander Motin #define ENC_VLOG if (enc_verbose) enc_log 225f6ad3f23SAlexander Motin #define ENC_MALLOC(amt) malloc(amt, M_SCSIENC, M_NOWAIT) 226f6ad3f23SAlexander Motin #define ENC_MALLOCZ(amt) malloc(amt, M_SCSIENC, M_ZERO|M_NOWAIT) 227f6ad3f23SAlexander Motin /* Cast away const avoiding GCC warnings. */ 228f6ad3f23SAlexander Motin #define ENC_FREE(ptr) free((void *)((uintptr_t)ptr), M_SCSIENC) 229f6ad3f23SAlexander Motin #define ENC_FREE_AND_NULL(ptr) do { \ 230f6ad3f23SAlexander Motin if (ptr != NULL) { \ 231f6ad3f23SAlexander Motin ENC_FREE(ptr); \ 232f6ad3f23SAlexander Motin ptr = NULL; \ 233f6ad3f23SAlexander Motin } \ 234f6ad3f23SAlexander Motin } while(0) 235f6ad3f23SAlexander Motin #define MEMZERO bzero 236f6ad3f23SAlexander Motin #define MEMCPY(dest, src, amt) bcopy(src, dest, amt) 237f6ad3f23SAlexander Motin 238f6ad3f23SAlexander Motin #endif /* __SCSI_ENC_INTERNAL_H__ */ 239